akhauriyash/Code-Regression huggingface dataset:
// const input = require('fs').readFileSync('/dev/stdin', 'utf8');
// const inputList = input.split('/'); // 空白文字に注意
// const inputNumberList = inputList.map(Number);

const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const inputList = input.split('\n');
// const inputNumberList = inputList.map(Number);

const N = inputList[0];
const xu= inputList.slice(1, -1);

let total = 0;

xu.forEach((i) => {
  const value = Number(i.split(' ')[0]);
  const unit = i.split(' ')[1];

  if (unit === 'JPY') {
    total += value;
  } else {
    total += (value * 380000.0);
  }
});

console.log(total);


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100005;

int S[maxn];
int n,q;

int main() {
	cin>>n>>q;
	for (int i=0;i<q;i++) {
		bool op; cin>>op;
		if (op) {
			int k; cin>>k;
			int ans=0;
			for (int i=k;i>0;i-=i&-i)
				ans+=S[i];
			cout<<ans<<'\n';
		}
		else {
			int s,t,x; cin>>s>>t>>x;
			for (int i=s;i<=n;i+=i&-i)
				S[i]+=x;
			for (int i=t+1;i<=n;i+=i&-i)
				S[i]+=-x;
		}
	}
}


Measured memory_bytes: 3440
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

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

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

int main(int argc, char** argv) {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i, H) {
    cin >> S[i];
  }
  // First, we want to calculate the all distance in width and heights
  vector< vector<int> > w_blocks(H);
  vector< vector<int> > h_blocks(W);
  rep(i, H) {
    w_blocks[i].push_back(-1);
    rep(j, W) {
      if (S[i][j] == '#') {
        w_blocks[i].push_back(j);
      }
    }
    w_blocks[i].push_back(W);
  }
  rep(j, W) {
    h_blocks[j].push_back(-1);
    rep(i, H) {
      if (S[i][j] == '#') {
        h_blocks[j].push_back(i);
      }
    }
    h_blocks[j].push_back(H);
  }

  // For Debug
  // cout << "w_blocks" << endl;
  // rep(i, H) {
  //   cout << i << ": ";
  //   for (auto e : w_blocks[i]) {
  //     cout << e << ", ";
  //   }
  //   cout << endl;
  // }
  // cout << "h_blocks" << endl;
  // rep(i, W) {
  //   cout << i << ": ";
  //   for (auto e : h_blocks[i]) {
  //     cout << e << ", ";
  //   }
  //   cout << endl;
  // }

  // Now, each w_block and h_block is sorted.
  int ans = 0;
  rep(i, H) {
    rep(j, W) {
      if (S[i][j] == '#') { continue; }

      int w, h;
      {
        auto w_i = upper_bound(all(w_blocks[i]), j);
        int r = *w_i;
        --w_i;
        int l = *w_i;
        w = r - l - 1;
      }
      {
        auto h_i = upper_bound(all(h_blocks[j]), i);
        int r = *h_i;
        --h_i;
        int l = *h_i;
        h = r - l - 1;
      }

      ans = max(ans, h + w - 1);
    }
  }

  cout << ans << endl;
}


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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

template <typename A, typename B>
string to_string(pair<A, B> p);
 
string to_string(const string& s) {
        return '"' + s + '"';
}
 
string to_string(const char* s) {
        return to_string((string) s);
}
 
string to_string(bool b) {
        return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
        bool first = true;
        string res = "{";
        for (int i = 0; i < static_cast<int>(v.size()); i++) {
                if (!first) {
                        res += ", ";
                }
                first = false;
                res += to_string(v[i]); 
        }
        res += "}";
        return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
        string res = "";
        for (size_t i = 0; i < N; i++) {
                res += static_cast<char>('0' + v[i]);
        }
        return res;
}
 
template <typename A>
string to_string(A v) {
        bool first = true;
        string res = "{";
        for (const auto &x : v) {
                if (!first) {
                        res += ", ";
                }
                first = false;
                res += to_string(x);
        }
        res += "}";
        return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
        return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
void debug_out() { 
        cerr << endl; 
}
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
        cerr << " " << to_string(H);
        debug_out(T...);
}
 
#ifdef IGM
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void solve() {
        int n;
        cin >> n;
        std::vector<int> p(n),q(n);
        FOR(i,0,n) cin >> p[i];
        FOR(i,0,n) cin >> q[i];
        std::vector<int> a(n);
        FOR(i,0,n) a[i] = i+1;
        int x  = 1, y = 1;
        int i = 2;
        while(next_permutation(all(a))) {
        	if(a == p) {
        		x = i;
        	}
        	if(a == q) {
        		y = i;
        	}
        	++i;

        }
        cout << abs(x-y) << endl;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
q=int(input())
s=sum(a)
d=Counter(a)
for i in range(q):
    b,c=map(int,input().split())
    if b in d:
        l=d[b]
        d[b]=0
        d[c]+=l
        s+=(c-b)*l
        print(s)
    else:print(s)

Measured memory_bytes: 21528
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

long long X;

int main()
{
  cin>>X;
  
  if(X>=30) cout<<"Yes";
  else cout <<"No";
  
}



Measured memory_bytes: 3632
// #include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
typedef long long ll;
typedef pair<int,int> Pii;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}

char maze[1005][1005];
int vis[1005][1005];
int c1,c2,d1,d2;
queue<Pii> q[2];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
 
int main(){
    int t=1;
    // read(t);
    while(t--){
        int h,w;
        read(h,w);
        read(c1,c2,d1,d2);
        for(int i=0;i<=h+1;i++){
            for(int j=0;j<=w+1;j++){
                maze[i][j]='#';
            }
        }
        for(int i=1;i<=h;i++){
            scanf("%s",maze[i]+1);
        }
        bool flag=true;
        vis[c1][c2]=1;
        int x=0,ans=0;
        q[x].push(Pii(c1,c2));
        while(1){
            while(!q[x].empty()){
                Pii now=q[x].front();
                q[x^1].push(now);
                q[x].pop();
                for(int i=0;i<4;i++){
                    int tx=now.first+dx[i];
                    int ty=now.second+dy[i];
                    if(!vis[tx][ty]&&maze[tx][ty]=='.'){
                        q[x].push(Pii(tx,ty));
                        q[x^1].push(Pii(tx,ty));
                        vis[tx][ty]=1;
                    }
                }
            }
            if(vis[d1][d2]){
                break;
            }
            x^=1;
            ans++;
            while(q[x].size()){
                Pii now=q[x].front();
                q[x].pop();
                for(int i=-2;i<=2;i++){
                    for(int j=-2;j<=2;j++){
                        int tx=now.first+i;
                        int ty=now.second+j;
                        if(tx<0||tx>h)continue;
                        if(ty<0||ty>w)continue;
                        if(!vis[tx][ty]&&maze[tx][ty]=='.'){
                            q[x^1].push(Pii(tx,ty));
                            vis[tx][ty]=1;
                        }
                    }
                }
            }
            if(vis[d1][d2]){
                break;
            }
            x^=1;
            if(q[x].empty()){
                flag=false;
                break;
            }
        }
        if(!flag){
            puts("-1");
            break;
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct UnionFind {
	int s, num; // [0, s) の s 個の要素がある。num は非空集合の個数。
	vector<vector<int>> v;
	vector<int> find;
	
	UnionFind(int s) { init(s); }
	void init(int arg_s) {
		num = s = arg_s;
		v.clear();
		find.clear();
		inc(i, s) { v.PB({i}); find.PB(i); }
	}
	bool unite(int x, int y) {
		assert(inID(x, 0, s) && inID(y, 0, s));
		if(find[x] == find[y]) { return false; }
		num--;
		if(v[find[x]].size() > v[find[y]].size()) { swap(x, y); }
		int fx = find[x];
		for(auto && e: v[find[x]]) { v[find[y]].PB(e); find[e] = find[y]; }
		v[fx].clear();
		return true;
	}
};

int n, m, a[50], b[50];

int main() {
	cin >> n >> m;
	inc(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
	
	UnionFind uf(n);
	int ans = 0;
	inc(i, m) {
		uf.init(n);
		inc(j, m) {
			if(j == i) { continue; }
			uf.unite(a[j], b[j]);
		}
		if(uf.num != 1) { ans++; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import math

def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
      if n % p == 0:
        return False
  return True

N=int(input())

result=1000000000000

i=1

if isPrime(N)==True:
    print(N-1)
else:
    for i in range(1,int(math.sqrt(N))+1):
        i+=1
        if(N%i==0):
            buf=i-1+N/i-1
            if(buf <= result):
                result=buf
    print(int(result))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rep3(i, m, n) for(ll i=m;i<=(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

ll sd[1005][1005];

#define MAX_V 1000005
struct edge {
	int to;
	int cost;
};
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P 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(P(d[e.to], e.to));
			}
		}
	}
}

void solve_abc_d() {
	ll h, w;
	ll l_ans = 0;

	cin >> h >> w;
	P c, dt;
	cin >> c.first >> c.second;
	cin >> dt.first >> dt.second;

	vector<string> meiro(h);
	rep(i, h) cin >> meiro[i];

	rep(i, 1005) rep(j, 1005) sd[i][j] = INF;
	
	// labeling
	ll label = 0;
	rep1(i, h) {
		rep1(j, w) {
			if (meiro[i-1][j-1] == '.') {
				if (sd[i][j] == INF) {
					label++;
				}

				queue<P> q;
				auto update = [&](ll ti, ll tj, ll td) {
					if (sd[ti][tj] != INF) return;
					sd[ti][tj] = td;
					q.push(P(ti, tj));
				};

				update(i, j, label);

				ll th, tw;
				ll nh, nw;
				// 探索方向
				int dw[] = { -1,0,1,0 }, dh[] = { 0,1,0,-1 };
				while (!q.empty()) {
					th = q.front().first;
					tw = q.front().second;
					q.pop();
					rep(k, 4) {
						nh = th + dh[k];
						nw = tw + dw[k];
						if (nh >= 1 && nh <= h && nw >= 1 && nw <= w) {
							if (meiro[nh-1][nw-1] == '.') {
								update(nh, nw, label);
							}
						}
					}
				}
			}
		}
	}

	// jump
	rep1(i, h) {
		rep1(j, w) {
			if (sd[i][j] != INF) {
				for (int ni = i - 2; ni <= i + 2; ni++)for (int nj = j - 2; nj <= j + 2; nj++) {
					if ((ni < 1) || (nj < 1)) {
						continue;
					}
					if (sd[ni][nj] != INF) {
						if (sd[ni][nj] != sd[i][j]) {
							edge e;
							e.cost = 1;
							e.to = sd[ni][nj];
							G[sd[i][j]].push_back(e);
						}
					}
				}
			}
		}
	}

	dijkstra(sd[c.first][c.second]);

	l_ans = d[sd[dt.first][dt.second]];
	if (l_ans == INF) l_ans = -1;

	cout << l_ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 65748
#include <stdio.h>

int main(void)
{
    int n;
    char s[1000];
    int count = 0;

    scanf("%d %s", &n, s);
    
    if (n % 2)
        printf("No");
    else {
        for (int i = 0; i < n/2; i++){
            if (s[i] == s[n/2 + i])
                count++;
        }
        if (count == n/2)
            printf("Yes");
        else
            printf("No");
    }

    return 0;


}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


signed main() {
	int n;
	vector<int>list;
	int maxn = 9999999;

	cin >> n;

	int sum = 0;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		list.push_back(num);
		sum += list[i];
	}

	int sum2 = 0;
	maxn = min(maxn, abs(sum2 - sum));
	for (int i = 0; i < n; i++) {
		sum -= list[i];
		sum2 += list[i];
			maxn = min(maxn, abs(sum2 - sum));
	}



	cout << maxn << endl;


	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = input()
N = int(N)

t_prev = 0
x_prev = 0
y_prev = 0

flag = True
for i in range(N ) : 
    s = input().split(" ")
    s = [int(i) for i in s]
    t = s[0]
    x  =s[1]
    y = s[2]
    
    eq = t - t_prev - abs(x - x_prev) - abs(y - y_prev)
    if eq < 0 : flag = False
    if eq % 2 == 1 : flag = False
    
    t_prev = t
    x_prev = x
    y_prev = y
    
if flag : print("Yes")
else : print("No")

Measured memory_bytes: 3064
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

m=I()
print(48-m)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator++() { return *this += mint(1); }
    mint& operator-=(const mint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator--() { return *this -= mint(1); }
    mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint& a) const { mint res(*this); return res+=a; }
    mint operator-(const mint& a) const { mint res(*this); return res-=a; }
    mint operator*(const mint& a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const {
        mint res = mint(1),a(*this);
        while(t > 0) {
            if(t&1) res *= a;
            t >>= 1;
            a *= a;
        }
        return res;
    }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { mint res(*this); return res/=a; }
};
ostream& operator<<(ostream& os,const mint& m) { return os << m.x; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi c(n);
    cin >> c;
    sort(rall(c));
    mint ans;
    rep(i,n) ans += ll(i+2)*c[i];
    ans *=  mint(2).pow(n*2-2);
    cout << ans << endl;
}


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

int main(){

	int A, B, C,i,j,k,x,y;
	cin >> A >> B >> C;

	i = A+B;
	j = A+C;
	k = B+C;

	x = min(i,j);
	y = min(i,k);

	cout << min(x,y) << '\n';

	return 0;

}

Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
s = input()
l = s.count('L')

count = 0
for i in range(n):
    if i > 0 and s[i] == s[i-1] == 'L':
        count += 1
    elif i < n - 1 and s[i] == s[i+1] == 'R':
        count += 1

ans = min(count + k*2, n - 1)
print(ans)

Measured memory_bytes: 10312
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> x(n);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        x[a[i]].push_back(i);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long s = x[i].size();
        ans += s * (s - 1) / 2;
    }
    for (int k = 0; k < n; k++) {
        long long s = x[a[k]].size();
        if (s > 1) {
            cout << ans - (s - 1) << endl;
        } else {
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 11008
//ABC 051-A
#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <numeric>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
	int K, S, X, Y, Z, ans = 0;
	cin >> K >> S;

	for (Z = min(K, S); Z >= max(S - 2 * K, 0); Z--) {
		Y = min(S - Z, K);
		X = S - Z - Y;
		ans += Y - X + 1;
	}
	cout << ans << endl;
}

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

int main()
{
    int N;
    std::string S;
    std::cin >>S;
    N=S.length();
    int count1=0;
    int count2=0;
    for(int i=0; i<N; i++){
        if(i%2==0){
            if(S[i] == '0'){
                count1++;
            }else{
                count2++;
            }
        }
        if(i%2==1){
            if(S[i] == '0'){
                count2++;
            }else{
                count1++;
            }
        }
    }
    int count;
    if(count1 > count2){
        count = count2;
    }else{
        count = count1;
    }
    std::cout << count <<std::endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;


vector<ll> Factorial(ll M, ll MOD){
    vector<ll> result = vector<ll>(M + 1);
    for(int i = 0; i <= M; i++){
        if(i == 0){
            result[i] = 1;
        }else{
            result[i] = result[i-1] * i % MOD;
        }
    }
    return result;
}

vector<ll> InvFact(ll M, ll MOD){
    vector<ll> result = vector<ll>(M + 1);
    vector<ll> inv = vector<ll> (M + 1);
    result[0] = 1;
    result[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < M; i++){
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        result[i] = result[i - 1] * inv[i] % MOD;
    }
    return result;
}

ll Combination(ll n,ll k,vector<ll>& fact, vector<ll>& invFact,ll MOD){
    //nCkを計算する
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
}

int main() {
    ll MOD = 1000000007;
    ll n;
    cin >> n;
    ll a[n + 1];
    ll isE[n];
    ll r;
    ll l;
    for (int i = 0; i < n; ++i) {
        isE[i] = -1;
    }
    for (int i = 0; i < n + 1; ++i) {
        cin >> a[i];
        if(isE[a[i] - 1] != -1){
            l = isE[a[i] - 1] + 1;
            r = i + 1;
        }
        isE[a[i] - 1] = i;
    }
    //cout << l << ", " << r << endl;
    auto fact = Factorial(n + 5,MOD);
    auto inv = InvFact(n + 5,MOD);
    //cout << Combination(0,0,fact,inv,MOD) << endl;
    for (int i = 1; i < n + 2; ++i) {
        cout << (Combination(n + 1,i,fact,inv,MOD) - Combination(l + n - r,i - 1,fact,inv,MOD) + MOD) % MOD << endl;
    }

}


Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int INF = 2e9;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN], b[MAXN];
int main() {
	read(n);
	int Min = INF;
	long long sum = 0;
	for (int i = 1; i <= n; i++) {
		read(a[i]), read(b[i]);
		sum += a[i];
		if (a[i] > b[i]) chkmin(Min, b[i]);
	}
	if (Min == INF) printf("0\n");
	else printf("%lld\n", sum - Min);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

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

    vector <int> val(N);

    for (int i = 0; i < N; ++i) {
        cin >> val[i];
    }

    for (int i = K; i < N; ++i) {
        if (val[i] > val[i-K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

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

  if (n == 1) {
    cout << 0 << '\n';
    return 0;
  }
  sort(a.begin(), a.end(), greater<ll>());
  ll ans = 0, cnt = 0;
  rep(i, n) {
    ans += a[i];
    cnt++;
    if (cnt == n - 1) break;
    if (i == 0) continue;
    ans += a[i];
    cnt++;
    if (cnt == n - 1) break;
  }
  cout << ans << '\n';
  




  
  return 0;
}

Measured memory_bytes: 4784
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	
	final long MOD =  (long)(1e9+7);
	
	int[] w, v;
	void solve() {
		int N = sc.nextInt();
		int W = sc.nextInt();
		w = new int[N];
		v = new int[N];
		for (int i = 0; i < N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		
		final long INF = 1L<<58;
		long[][] dp = new long[N+1][301];
		for (int i = 0; i < dp.length; i++) 
			Arrays.fill(dp[i], -INF);
		dp[0][0] = 0;
		for (int i = 0; i < N; i++) {
			for (int nn = N-1; nn >= 0; nn--) {
				for (int ww = 0; ww <= 300; ww++) {
					int ww2 = ww + (w[i] - w[0]);
					if (ww2 <= 300) 
						dp[nn+1][ww2] = max(dp[nn+1][ww2], dp[nn][ww] + v[i]);
				}
			}
		}
		
		long ans = 0;
		for (int n = 0; n <= N; n++) {
			long WW = W - (long)n * w[0];
			if (WW < 0) continue;
			if (WW > 300) WW = 300;
			for (int w = 0; w <= WW; w++)
				ans = max(ans, dp[n][w]);
		}
		out.println(ans);
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 21972
#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;
    cin >> n;
    int cnt = 0;
    bool ans = false;
    rep(i,n){
        int a, b;
        cin >> a >> b;
        if(a==b) cnt++;
        else cnt=0;
        if(cnt==3) ans = true;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>

int main(){
	int min_ps=30000,min_j=30000,temp;

	for(int i=0;i<5;i++){
		scanf("%d",&temp);
		if(min_ps > temp && i < 3){
			min_ps = temp;
		}
		else if(min_j > temp){
			min_j = temp;
		}
	}
	printf("%d\n",min_ps+min_j-50);
	return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

int color[MAX];
bool M[MAX][MAX];
int n;
int tt;
int d[MAX];
int f[MAX];

void dfs(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	for (int v = 0; v < n; v++) {
		if (M[u][v] && color[v] == WHITE) {
			dfs(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_init() {
	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
	}
	tt = 0;
	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) {
			dfs(u);
		}
	}
	for (int u = 0; u < n; u++) {
		cout << u + 1 << " ";
		cout << d[u] << " " << f[u] << endl;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = false;
		}
		d[i] = f[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			M[u - 1][v - 1] = true;
		}
	}
	
	dfs_init();

	return 0;
}


Measured memory_bytes: 3128
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np


def main():
	n=II()
	a=n%10

	if a in [2,4,5,7,9]:
		print("hon")
	elif a in [0,1,6,8]:
		print("pon")
	else:
		print("bon")












if __name__ == "__main__":
	main()


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

const int MAX_N = (int)(40 + 5);
const int MAX_UNIT = (int)(400 + 5);

struct matter {int a, b, c;};

int n, ma, mb;
matter items[MAX_N];

int dp[MAX_N][MAX_UNIT][MAX_UNIT];

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d %d", &n, &ma, &mb);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d %d", &(items[i].a), &(items[i].b), &(items[i].c));
  }

  for (int i = 0; i <= n; ++i) {
    for (int ua = 0; ua <= MAX_UNIT - 1; ++ua) for (int ub = 0; ub <= MAX_UNIT - 1; ++ub) {
      dp[i][ua][ub] = -1;
    }
  }

  dp[0][0][0] = 0;

  for (int i = 1; i <= n; ++i) {
    for (int ua = 0; ua <= MAX_UNIT - 1; ++ua) for (int ub = 0; ub <= MAX_UNIT - 1; ++ub) {
      dp[i][ua][ub] = dp[i - 1][ua][ub];
      if ((ua - items[i].a) >= 0 && (ub - items[i].b) >= 0 && dp[i - 1][ua - items[i].a][ub - items[i].b] > -1) {
        int cand = dp[i - 1][ua - items[i].a][ub - items[i].b] + items[i].c;
        dp[i][ua][ub] = (dp[i][ua][ub] > -1) ? min(dp[i][ua][ub], cand) : cand;
      }
      else {
        if (ua == items[i].a && ub == items[i].b) {
          dp[i][ua][ub] = (dp[i][ua][ub] > -1) ? min(dp[i][ua][ub], items[i].c) : items[i].c;
        }
      }

    }
  }

  ans = 114514;
  for (int ua = 1; ua <= MAX_UNIT - 1; ++ua) {
    for (int ub = 1; ub <= MAX_UNIT - 1; ++ub) {
      if ((ua * mb) == (ma * ub)) {
      // if ((ua / ma) == (ub / mb) && (ua % ma) == 0 && (ub % mb) == 0) {
        ans = dp[n][ua][ub] > -1 ? min(ans, dp[n][ua][ub]) : ans;
      }
    }
  }

  ans = ans == 114514 ? -1 : ans;

  printf("%d\n", ans);

  return 0;
}

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

main()
{
    int i,A,B,K,cnt=0,ans;
    cin >> A >> B >> K;
    if(A < B){
        swap(A,B);
    }
    for(i=B;i>0;i--){
        if(A%i==0&&B%i==0){
            cnt++;
        }
        if(cnt==K){
            ans = i;
            break;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  i32 *dp = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = 1; i <= n; ++i) {
    dp[i] = i;
  }
  while (m--) {
    i32 c;
    scanf ("%" SCNi32, &c);
    for (i32 i = c; i <= n; ++i) {
      if (dp[i] > dp[i - c] + 1) {
	dp[i] = dp[i - c] + 1;
      }
    }
  }
  printf ("%" PRIi32 "\n", dp[n]);
}

int main (void) {
  run ();
  return 0;
}



Measured memory_bytes: 2108
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
/*inline T gcd(T a,T b){
	while(b != 0 ){
		a = a % b;
		swap(a,b);
	}
	return a;
}*/

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////

LL mod = 1000000007;

inline void solve(){
	LL N;
	cin >> N;
	LL ans = 1;
	for(LL i=1;i<=N;++i){
		ans = (ans*i)%mod;
	}
	cout << ans << endl;
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 384
#include <stdio.h>
int main(){
  int a,b,c,i;
  int cnt=0;;
  scanf("%d %d %d",&a,&b,&c);
  for(i=a;i<=b;i++){
    if(c%i==0){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  return(0);
}

Measured memory_bytes: 596
length = gets.to_i
array = gets.split(" ").map(&:to_i)
result = 0
count = 0

(1..length).each do |i|
  if i == length
    result = count if result < count
    break
  end

  if array[i] <= array[i - 1]
    count += 1
  else
    result = count if result < count
    count = 0
  end
end

puts result

Measured memory_bytes: 8580
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int mod = 1000000007;

int main(){
    string s; cin >> s;
    int n = s.size();
    int w = 0;
    ll ans = 0;
    rep(i,n){
        if (s[i] == 'W'){
            ans += i - w;
            w++;
        }
    }
    cout << ans << endl;
}

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

int main(){
  string S,T;
  int A,B;
  string U;
  cin>>S>>T>>A>>B>>U;
  if(S==U) A-=1;
  else if(T==U) B-=1;
  cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int min(int a,int b){
  return a<b?a:b;
}
int main(void){
  int p1,p2,p3,pm,j1,j2,jm;
  scanf("%d %d %d %d %d",&p1,&p2,&p3,&j1,&j2);
  pm=min(p1,min(p2,p3));
  jm=min(j1,j2);
  printf("%d\n",pm+jm-50);
  return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> vec(N);
    int mi = 1;
    for(int i=0; i<N; i++){
        cin >> vec[i];
        if(vec[i]==1){
            mi = i;
        }
    }

    int ans= 214700000;
    for(int i=0; i<K; i++){
        int count=1;
        int migi = mi +K-1 -i;
        while(migi<N-1){
            migi += K-1;
            count++;
        }
        int hidari=mi -i;
        while(hidari>0){
            hidari -= K-1;
            count++;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	i64 n, k, ans;
	cin >> n >> k;
	ans = k;
	ans *= pow((k - 1), (n - 1));
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	rep(i,n) cin >> c[i];
	sort(a.begin(), a.end());
	sort(c.begin(), c.end());
	ll ans = 0;
	rep(i,n) {
		ll A = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		ll C = c.end()	- upper_bound(c.begin(),c.end(), b[i]);
		ans += A*C;
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4580
import java.io.*;
class Main{
	public static void main(String[] args) throws IOException {
		int i;
		int[] n = new int[5];
		String[] str = new String[5];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<3;i++)
			n[i] = Integer.parseInt(str[i]);
		System.out.println((n[0]<n[1] && n[1]<n[2]) ? "Yes" : "No");
	}
}

Measured memory_bytes: 24196
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N,X;
    cin>>N>>X;
    v m(N);
    rep(i,0,N)cin>>m[i];
    sort(all(m));
    ll sum = 0;
    rep(i,0,N){
        sum += m[i];
    }
    cout<<N+(X-sum)/m[0];
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int getint()
{
    int i=0,f=1;char c;
    for(c=getchar();(c!='-')&&(c<'0'||c>'9');c=getchar());
    if(c=='-')c=getchar(),f=-1;
    for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0';
    return i*f;
}
const int N=200005,mod=1e9+7;
const ll INF=1e18;
int n,m,A,B,q[N];
ll f[N<<2],g[N<<2],h[N<<2],tag[N<<2];
void add(int k,ll v){if(f[k]!=INF)f[k]+=v,g[k]+=v,h[k]+=v,tag[k]+=v;}
void pushdown(int k){add(k<<1,tag[k]),add(k<<1|1,tag[k]);tag[k]=0;}
void update(int k)
{
    f[k]=min(f[k<<1],f[k<<1|1]);
    g[k]=min(g[k<<1],g[k<<1|1]);
    h[k]=min(h[k<<1],h[k<<1|1]);
}
void build(int k,int l,int r)
{
    f[k]=g[k]=h[k]=INF;
    if(l==r)return;
    int mid=l+r>>1;
    build(k<<1,l,mid),build(k<<1|1,mid+1,r);
}
void chkmin(int k,int l,int r,int p,ll v)
{
    if(l==r)
    {   
        if(v<f[k])f[k]=v,g[k]=v-l,h[k]=v+l;
        return;
    }
    if(tag[k])pushdown(k);
    int mid=l+r>>1;
    p<=mid?chkmin(k<<1,l,mid,p,v):chkmin(k<<1|1,mid+1,r,p,v);
    update(k);
}
ll query(int k,int l,int r,int x,int y,int op)
{
    if(x>y)return INF;
    if(x<=l&&r<=y)return op?h[k]:g[k];
    if(tag[k])pushdown(k);
    int mid=l+r>>1;
    if(y<=mid)return query(k<<1,l,mid,x,y,op);
    else if(x>mid)return query(k<<1|1,mid+1,r,x,y,op);
    else return min(query(k<<1,l,mid,x,mid,op),query(k<<1|1,mid+1,r,mid+1,y,op));
}
int main()
{
    //freopen("lx.in","r",stdin);
    n=getint(),m=getint(),A=getint(),B=getint();
    build(1,1,n);
    for(int i=1;i<=m;i++)q[i]=getint();
    q[0]=B;chkmin(1,1,n,A,0);
    for(int i=1;i<=m;i++)
    {
        ll tmp=min(query(1,1,n,1,q[i],0)+q[i],query(1,1,n,q[i]+1,n,1)-q[i]);
        add(1,abs(q[i]-q[i-1]));chkmin(1,1,n,q[i-1],tmp);
    }
    cout<<f[1]<<'\n';
    return 0;
}

Measured memory_bytes: 25728
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
M = max(A)
for i in range(N):
    e = A[i]
    if Cs[e]==1:
        Cs[e]=2
    elif Cs[e]==0:
        Cs[e]=1

for i in range(len(Cs)):
    Cs[i] = Cs[i]%2

for e in A:
    i = 2
    while e*i <= M:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)


Measured memory_bytes: 164396
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 
int main(){
  int D;
  cin >> D;
  vector<int> c(26, 0);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26, 0));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }

  int type = 1;
  int cnt = 0;
  while(cnt < D){
    cout << type << endl;
    type = type % 26 + 1;
    cnt++;
  }

    
}


Measured memory_bytes: 3680