akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

ll sum(int a) {
	if (a < 10)
		return a;
	return (a%10) + sum(a/10);
}

int main() {
	ll ans = 1000000000;
	int n;
	cin >> n;
	for (int i = 1; i <= n-1; ++i)
		ans = min(ans, sum(i) + sum(n-i));
	cout << ans << endl;
}

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

from collections import Counter


ans={}
for i in range(n):
    s = input()

    c= dict(Counter(s))

    if i==0:
        ans=c
    else:
        ans_merge = ans.copy()

        delete=[]

        for k,v in ans_merge.items():
            if k in c:
                ans_merge[k] = min(ans_merge[k],c[k])
            else:
                delete.append(k)

        for j in delete:
            del ans_merge[j]

        ans = ans_merge

ans = sorted(ans.items(),key=lambda x:x[0])

string=''

for k in ans:
    string+=k[0]*k[1]

print(string)

Measured memory_bytes: 3316
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 500005
using namespace std;
inline int read(){
	int sum = 0, t = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') t = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ sum = sum * 10 + ch - '0'; ch = getchar(); }
	return sum * t;
}

int pre[N], suf[N];
int n, D, q, d[N];

int main(){
	n = read(); D = read();
	for(int i = 1; i <= n; i++)
		d[i] = read();
	q = read();
	suf[n + 1] = 1;
	for(int i = n; i ; i--)
		if(d[i] / 2 < suf[i + 1]) suf[i] = d[i] + suf[i + 1];
		else suf[i] = suf[i + 1];
	pre[0] = D;
	for(int i = 1; i <= n; i++)
		if(abs(pre[i - 1] - d[i]) < pre[i - 1]) pre[i] = abs(pre[i - 1] - d[i]);
		else pre[i] = pre[i - 1];
	for(; q ; q--){
		int x = read();
		puts(pre[x - 1] >= suf[x + 1] ? "YES" : "NO");
	}
}

Measured memory_bytes: 7680
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length
    
    val mod = Array(n) { 1 }
    for (i in 1 until n) {
        mod[i] = 10*mod[i-1]%2019
    }

    val t = Array(n+1) { 0 }
    for (i in n-1 downTo 0) {
        val tmp = Integer.parseInt(s[i].toString())
        t[i] = (t[i+1] + mod[n-i-1]*tmp)%2019
    }
    
    val map = mutableMapOf(0 to 0)
    t.forEach { if(map.containsKey(it)) map[it] = map[it]!!+1 else map[it] = 1 }
    
    var res = 0
    for (item in map) {
        val m = item.value
        res += m*(m-1)/2
    }
    
    println(res)
}


Measured memory_bytes: 61956
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;


const long double PI = 3.14159265358979323846264338327950;
const double EPS = 1e-9;
const int N = 100000;

template <class T> T gcd(T a, T b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}

template <class T> bool isPrime(T x) {
	for (T d = 2; d * d <= x; d++) { if (x % d == 0) return false; }
	return true;
}


int arr[N + 1];

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

	int n, m, q, b, c;
	long long ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> m;
		++arr[m];
		ans += m;
	}

	cin >> q;
	while (q--) {
		cin >> b >> c;
		ans -= (long long)b * arr[b];
		ans += (long long)c * arr[b];
		arr[c] += arr[b];
		arr[b] = 0;
		cout << ans << '\n';
	}
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;

ll sum[5001], mx[5001];
ll len[5001];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    ll c[n], p[n];
    for(ll i=0; i<n; i++)
    {
        cin >> p[i];
        p[i]--;
    }
    for(ll i=0; i<n; i++)
    {
        cin >> c[i];
        mx[i] = LLONG_MIN;
    }
    for(ll i=0; i<n; i++)
    {
        ll t = 0;
        ll ind = i;
        ll ctr = 0;
        bool seen[n];
        memset(seen, false, sizeof(seen));
        while(!seen[ind])
        {
            seen[ind] = true;
            t += c[ind];
            mx[i] = max(mx[i], t);
            ctr++;
            ind = p[ind];
        }
        sum[i] = t;
        len[i] = ctr;
    }
    ll ans = LLONG_MIN;
    for(ll i=0; i<n; i++)
    {
        if(len[i] < k)
        {
            ans = max(ans, mx[i]);
//            what_is(i);
//            what_is(len[i]);
//            what_is(sum[i]);
            if(sum[i] > 0)
            {
                ll b = k;
                ll t = 0;
                ll ind = i;
                ll ctr = 0;
                ll num = (b-len[i])/len[i];
                ans = max(ans, num*sum[i] + mx[i]);
                b%=len[i];
                t = (num+1)*sum[i];
                while(b)
                {
                    ans = max(ans, t);
                    b--;
                    t += c[ind];
                    ind = p[ind];
                }
                ans = max(ans, t);
            }
        }
        else
        {
            ll t = 0;
            ll ind = i;
            ll ctr = 0;
            while(ctr < k)
            {
                t += c[ind];
                ans = max(ans, t);
                ctr++;
                ind = p[ind];
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  map<int, int> s;

  ll ans = 0;

  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;

    s[temp]++;
  }

  for (auto it = s.begin(); it != s.end(); it++) {
    if (it->first > it->second) {
      ans += it->second;
    } else {
      ans += (it->second - it->first);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 7960
S = int(input())
L = S // 100
R = S % 100
if 1 <= L <= 12 and 1 <= R <= 12:
  print("AMBIGUOUS")
elif 1 <= L <= 12 and (R >= 13 or R == 0):
  print("MMYY")
elif (L >= 13 or L == 0) and 1 <= R <= 12:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[101],d,f,g[101],h,i,j,z;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<=a;i++) scanf("%d",&s[i]);
		for(i=0;i<=a;i++){
			d=0;
			for(j=0;j<=a;j++){
				if(i!=j){
					g[d]=s[j];
					d++;
				}
				if(i==j)
					z=s[i];
			}
			h=0;
			f=g[a-2]-g[a-3];
			for(j=a-1;j>0;j--){
				if(g[j]-g[j-1]!=f){
					h=1;
					break;
				}
			}
			if(h==0){
				printf("%d\n",z);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2712
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll l, r, d;
  cin >> l >> r >> d;
  cout << r/d - (l-1)/d << newl;
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void){
	int i,l,a,b,f,t[1000],c[1000],r[1000];
	
	for(i=0;;i++){
		scanf("%d,%d",&t[i],&c[i]);
		if(t[i]==0 && c[i]==0)break;
	}
	
	for(f=1,i=30;i>=0;i--){
		a=0;
		for(l=0;;l++){
			if(t[l]==0 && c[l]==0)break;
			else if(c[l]==i){
				r[l]=f;
				a++;
			}
		}
		if(a!=0)f++;
	}
	
	
	while(scanf("%d",&f)!=EOF){
		
		for(i=0;;i++){
			if(f==t[i]){
				printf("%d\n",r[i]);
				break;
			}
		}
	}
	return 0;
}
	
		
		
		
	
	

Measured memory_bytes: 612
const input = require('fs').readFileSync('/dev/stdin', 'UTF-8');

const circleInARectangle = input => {
  const [W, H, x, y, r] = input.split(' ').map(val => Number(val));
  const horizontallyInside = r <= x && x <= W - r;
  const verticallyInside = r <= y && y <= H - r;

  const result = horizontallyInside && verticallyInside ? 'Yes' : 'No';
  console.log(result);
};

circleInARectangle(input);



Measured memory_bytes: 15140
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  int t[n];
  rep(i,n)cin >> t[i];
  int a[n];
  rep(i,n)cin >> a[i];
  ll ans=1;
  bool flag[n]={},flag2[n]={};
  int sup[n]={};
  rep(i,n){
    if(i==0){
      flag[i]=true;
    }
    else{
      if(t[i]>t[i-1]){
        flag[i]=true;
      }else{
        sup[i]=t[i];
      }
    }
  }
  for(int i=n-1;i>=0;i--){
    if(i==n-1){
      flag2[i]=true;
    }
    else{
      if(a[i]>a[i+1]){
        flag2[i]=true;
      }else{
        if(!flag[i]){
          sup[i]=min(sup[i],a[i]);
        }else{
          if(t[i]>a[i]){
            cout << 0 << endl;
            return 0;
          }
        }
      }
    }
  }
  rep(i,n){
    if(!flag[i] && !flag2[i]){
      ans*=sup[i];
      ans%=mod;
    }
  }
  if(t[n-1]!=a[0])ans=0;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 1664
//file_name:ABC108_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&y);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */


int main() {
    int x1;
    scanf("%d",&x1);
    int y1;
    scanf("%d",&y1);
    int x2;
    scanf("%d",&x2);
    int y2;
    scanf("%d",&y2);

    int x3 = 0;
    int y3 = 0;
    int x4 = 0;
    int y4 = 0;

    x3 = x2 + y1 - y2;
    y3 = y2 - x1 + x2;
    x4 = x3 + x1 - x2;
    y4 = y3 + y1 - y2;

    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    rep(i, n - 2) {
        if ((s[i] == 'A') && (s[i + 1] == 'B') && (s[i + 2] == 'C')) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, Z, W = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
 
if N == 1
  puts ( A[0] - W ).abs
  exit
end
 
e = ( A[-1] - W ).abs
b1 =  ( A[-2] - A[-1] ).abs 
 
if e > b1
  puts e
else 
  puts b1
end

Measured memory_bytes: 1788
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define psi std::pair<string,int>
#define pli std::pair<ll,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%I64d",&x)
#define prll(x) printf("%I64d ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vli std::vector<std::list<int>>
#define vlpi vector<list<pii>>
#define li std::list<int>
#define Endl printf("\n")
#define ma 1000000
#define mod 786433
#define FOR(i,a) for(int i=0; i<a; i++)
#define FORL(i,a) for(ll i=0 ;i<a ; i++)
#define MAXN 1000
#define paire(a,b)  make_pair(a,b)

using namespace std;

int main()
{
    int n ; cin >> n ;
    if (n==2){
        ll x ; cin >> x ;
        cout << 2 * x ;
    }
    else {
    vll a ;
    FOR(i,n-1) {
        ll x ; cin >> x ;
        a.pb(x) ;
       }

    ll s ;
    if (a[0]>a[1]){
        s=a[0] ;
        for(int i=1; i<n-1 ; i++) {
        s+=min(a[i],a[i-1]);
    }
    }
        else {
        s=a[0];
        for(int i=1; i<n-1 ; i++) {
        s+=min(a[i],a[i-1]);
        }
    }

    s+=a[n-2] ;
    cout << s ;

    }
}







Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

int main(int argc, char const *argv[])
{
    double x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double d = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    printf("%lf\n", d);
    return 0;
}

Measured memory_bytes: 1236
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let mut set = HashMap::new();
    for _ in 0..n {
        let str: String = read();
        let mut str = str.chars().collect::<Vec<_>>();
        str.sort();
        *set.entry(str).or_insert(0) += 1;
    }
    let mut sum = 0;
    for (_, num) in set {
        sum += comb_2(num);
    }
    println!("{}", sum);
}

fn comb_2(n: i32) -> i64 {
    let n: i64 = n as i64;
    n * (n - 1) / 2
}


Measured memory_bytes: 16636
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,l,x,now=0,Ans=1;
	scanf("%d%d",&n,&x);
	for(int i=1; i<=n; i++) {
		scanf("%d",&l);
		now+=l,Ans+=now<=x;
	}
	printf("%d",Ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  string S;
  cin >> S;

  string T = S;
  reverse(all(T));

  int N = S.size();
  int i = N / 2;
  char mid = S[i];
  while (i < N && T[i] == S[i] && S[i] == mid) {
    i++;
  }
  cout << i << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long X, S = 100;

int main() {
	cin >> X;
	for (int i = 1; i <= 100000; i++) {
		S += 1LL * S / 100LL;
		if (S >= X) { cout << i << endl; break; }
	}
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll m; cin>>m;
    vector<LP> dc(m); cin>>dc;

    ll d = 0;
    rep(i, m) d += dc[i].se;

    ll s = 0;
    rep(i, m) s += dc[i].fi * dc[i].se;

    ll ans = d - 1 + (s - 1) / 9;
    cout<<ans<<endl;
}

Measured memory_bytes: 3456
def tax_included(price, tax)
  (price.to_f * (100 + tax) / 100).floor
end

def find_original_price(price, tax)
  (1..price).to_a.select { |orig| tax_included(orig, tax) == price }
end

loop do
  x, y, s = gets.chomp.split.map(&:to_i)
  break if x.zero? && y.zero? && s.zero?

  max = 0
  (1..(s / 2)).each do |p1|
    p2 = s - p1

    o1 = find_original_price(p1, x)
    o2 = find_original_price(p2, x)
    o1.each do |i|
      o2.each do |j|
        p = tax_included(i, y) + tax_included(j, y)
        max = [max, p].max
      end
    end
  end

  puts max
end

Measured memory_bytes: 45300
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

//int N;
vector<ll> h(100010);
vector<ll> dp(100010, INFL);

ll rec(ll i){
if(dp[i]<INFL) return dp[i];

  if(i==0) return 0;

  ll res = INF;
  res = min(res,rec(i-1)+abs(h[i]-h[i-1]));
  if(i>1)res = min(res,rec(i-2)+abs(h[i]-h[i-2]));
  return dp[i]=res;
}

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

  cout << rec(N-1)<<endl;

}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int n,res,small=1000,s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>s;
		res+=s;
		if (s%10!=0) small=min(small,s);
	}
	if (small==1000) cout<<"0";
	else if (res%10==0) cout<<res-small;
	else cout<<res;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = parseInt(input[0][0], 10);
    ans = Math.ceil(N / 1000) * 1000 - N;
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 29684
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

char stage[1000][1000],emblem[2][2];
int latte[1000][1000][3],ans,mx;

void JOI_cmp(int y,int x){
    int cy,cx,cnt=0;
    char cc;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            if(stage[y+i][x+j]!=emblem[i][j]){
                cnt++;
                cy=y+i; cx=x+j; cc=emblem[i][j];
                if(cc=='J') cc=0;
                else if(cc=='O') cc=1;
                else cc=2;
                if(cnt>1) break;
            }
        }
    }
    if(cnt==0){
        ans++;
        for(int i=0;i<2;i++){
            for(int j=0;j<2;j++){
                for(int k=0;k<3;k++){
                    latte[y+i][x+j][k]--;
                }
            }
        }
    }
    if(cnt==1){
        //printf(" %d,%d\n",y,x);
        latte[cy][cx][cc]++;
        mx=max(mx,latte[cy][cx][cc]);
    }
    return;
}

int main(){
    int M,N;
    cin>>M>>N;
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++){
            cin>>stage[i][j];
        }
    }
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            cin>>emblem[i][j];
        }
    }
    for(int i=0;i<M-1;i++){
        for(int j=0;j<N-1;j++){
            JOI_cmp(i,j);
        }
    }
    printf("%d\n",ans+mx);
    return 0;
}

Measured memory_bytes: 13844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vi a(n); cin >> a;
	vector<pii> b;
	int zero = 0;
	REP(i, n)
	{
		if (a[i] == 0) zero++;
		else
		{
			if (zero > 0) b.emplace_back(0, zero);
			zero = 0;
			b.emplace_back(a[i], 1);
		}
	}
	if(zero > 0) b.emplace_back(0, zero);
	int m = b.size();
	ll ans = 0;
	REP(i, m)
	{
		int cnt = 0;
		int tmp = 0;
		FOR(j, i, m)
		{
			if (b[j].first == 0)
			{
				cnt += b[j].second;
			}
			else if ((b[j].first & tmp) == 0)
			{
				cnt++;
				tmp |= b[j].first;
			}
			else
			{
				break;
			}
		}
		if (b[i].first == 0)
		{
			REP(j, b[i].second) ans += cnt - j;
		}
		else
		{
			ans += cnt;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#define INT long long int
using namespace std;
string s;
int cnt, pre, n;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>s;
    for(int i = 0 ; i < s.size() ; i++ )
    {
        if( s[i] == '(' ) cnt++;
        else if( cnt > 0 ) cnt--;
        else pre++;
    }
    while( pre ) cout<<"(", pre--;
    cout<<s;
    while( cnt ) cout<<")", cnt--;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> amari;
  long long amarism = 0;
  long long want = 0;
  int ans = 0;
  int a[n],b[n];
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  for(int i = 0; n > i; i++){
	cin>>b[i];
  }
  for(int i = 0; n > i; i++){
	if(a[i] > b[i]){
      amari.push_back(a[i]-b[i]);
      amarism += a[i]-b[i];
    }else{
      want += b[i]-a[i];
      ans++;
    }
  }
  if(want > amarism){
    cout << -1 << endl;
    return 0;
  }
  if(want == 0){
    cout << 0 << endl;
    return 0;
  }
  sort(amari.begin(),amari.end(),greater<int>());
  for(int i = 0; amari.size() > i; i++){
    ans++;
    if(want > amari[i]){
      want -= amari[i];
    }else{
      cout << ans << endl;
      return 0;
    }
  }
}
  
  

Measured memory_bytes: 1408
# Contest No.: M-SOLUTIONS Programming Contest 2020
# Problem No.: B
# Solver:      JEMINI
# Date:        20200725

import sys
import heapq

def main():
    a, b, c = map(int, input().split())
    k = int(input())
    cnt = 0
    while cnt <= k and a >= b:
        b *= 2
        cnt += 1
    if cnt > k:
        print("No")
        return
    while cnt <= k and b >= c:
        c *= 2
        cnt += 1
    if cnt > k:
        print("No")
    else:
        print("Yes")

    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 62224
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i];
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,ar[N],sum;
int m,a,r,c,h;
char s[N];


int main()
{
	fast;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s+1;

		if(s[1]=='M')
			ar[1]++;
		if(s[1]=='A')
			ar[2]++;
		if(s[1]=='R')
			ar[3]++;
		if(s[1]=='C')
			ar[4]++;
		if(s[1]=='H')
			ar[5]++;

	}
	for(int i=1;i<=5;i++)
		for(int j=i+1;j<=5;j++)
			for(int h=j+1;h<=5;h++)
			{
				sum+=ar[h]*ar[j]*ar[i];
			}
	cout<<sum;



}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, const char * argv[]) {
    
    const int BUF_SIZE = 26 ;
    
    char alphabets[BUF_SIZE] ;
    char bigAlphabets[BUF_SIZE] ;
    char counter[BUF_SIZE] ;
    
    for (char alf='a'; alf<='z'; alf++) {
        alphabets[alf-'a'] = alf ;
        bigAlphabets[alf-'a'] = alf-32 ;
        counter[alf-'a'] = 0;
    }
    
    char ch ;
    
    while ( scanf("%c", &ch) != EOF ) {
        for (int i=0; i<BUF_SIZE; i++) {
            if ( ch == alphabets[i] || ch == bigAlphabets[i]) {
                counter[i] ++ ;
                break ;
            }
        }
    }
    
    for (int i=0; i<BUF_SIZE; i++) {
        printf("%c : %d\n", alphabets[i], counter[i]) ;
    }
    
    return 0 ;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< int > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if (n == 2) {
        cout << a[1] - a[0] << endl;
        cout << a[1] << " " << a[0] << endl;
        return 0;
    }
    if (a[0] * a[n - 1] < 0) {
        int j = n - 1, ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] > 0)
                j = min(j, i);
            ans += (a[i] < 0 ? -1 * a[i] : a[i]);
        }
        cout << ans << endl;
        int tmp = a[0];
        for (int i = j; i < n - 1; i++) {
            cout << tmp << " " << a[i] << endl;
            tmp -= a[i];
        }
        cout << a[n - 1] << " " << tmp << endl;
        tmp = a[n - 1] - tmp;
        for (int i = 1; i < j; i++) {
            cout << tmp << " " << a[i] << endl;
            tmp -= a[i];
        }
    } else {
        if (a[0] + a[n - 1] < 0) {
            reverse(a.begin(), a.end());
            int ans = a[0];
            for (int i = 1; i < n; i++) {
                ans -= a[i];
            }
            cout << ans << endl;
            int tmp = a[0];
            for (int i = 1; i < n; i++) {
                cout << tmp << " " << a[i] << endl;
                tmp -= a[i];
            }
        } else {
            int ans = -1 * a[0];
            for (int i = 1; i < n; i++) {
                ans += a[i];
            }
            cout << ans << endl;
            int tmp = a[0];
            for (int i = 1; i < n - 1; i++) {
                cout << tmp << " " << a[i] << endl;
                tmp -= a[i];
            }
            cout << a[n - 1] << " " << tmp << endl;
        }
    }

    return 0;
}


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


int main(){
    int m,d;
    cin >> m >> d;
    
    int answer = 0;
    
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= d; j++){
            int seki;
            string seki_s;
            seki_s = to_string(j);
            if(seki_s.size() == 1)seki = 0;
            else{
                int d1 = seki_s.at(0) - '0';
                int d10 = seki_s.at(1) - '0';
                if(d1 >= 2 && d10 >= 2){
                    seki = d1 * d10;
                }else{
                    seki = 0;
                }
            }
            
            if(i == seki)answer++;
            
        }
    }
    
    cout << answer << endl;
}

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

int main(){
  ll a,b,x;
  cin >> a >> b >> x;
  ll ans;

  if (a == 0) {
    printf("%lld\n", b/x+1);
  }else{
    printf("%lld\n", b/x-(a-1)/x);
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int mod=993244853;
const int base=131;
const int MAXN=200005;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;	
}
int a[MAXN],b[MAXN],n;
int main()
{
	n=read();
	int temp=pow_mod(base,n-2);
	for(int i=0;i<n;i++)b[i]=read();
	for(int i=0;i<n;i++)a[i]=read();
	if(n==1)return pr2(1),0;int sum=0;
	for(int i=0;i<n-1;i++)sum=(1LL*sum*base+(a[i]^a[i+1]))%mod/*,pr1(a[i]^a[i+1])*/;
//	puts("");
	int ans=0;int sum1=0;
	for(int i=0;i<n-1;i++)sum1=(1LL*sum1*base+(b[i]^b[i+1]))%mod/*,pr1(b[i]^b[i+1])*/;
//	puts("");
	b[n]=b[0];a[n]=a[0];
	for(int i=0;i<n;i++)
	{
		if(sum==sum1)
		{
			pr1(i);pr2(a[0]^b[i]);
		}
		sum1=(sum1-1LL*(b[i]^b[i+1])*temp%mod+mod)%mod;
		sum1=1LL*sum1*base%mod;
		sum1=(sum1+(b[(i+n-1)%n]^b[(i+n)%n]))%mod;
	}
	return 0;
}


Measured memory_bytes: 4864
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[5];
		long total = 0;

		for (int i = 0; i < n; i++) {
			char s = sc.next().charAt(0);
			switch (s) {
				case 'M':
				a[0]++;
				break;
				case 'A':
				a[1]++;
				break;
				case 'R':
				a[2]++;
				break;
				case 'C':
				a[3]++;
				break;
				case 'H':
				a[4]++;
				break;
			}
		}

		long answer = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = i + 1; j < 4; j++) {
				for (int k = j + 1; k < 5; k++) {
					answer += a[i] * a[j] * a[k];
				}
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 46120
#include <map>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  int n = getInt();
  vector<int> p(n);
  map<int, int> ans;
  vector<int> res(n);

  REP(i,n * (n - 1) / 2){
    int a = getInt();
    int b = getInt();
    int c = getInt();
    int d = getInt();

    p[a - 1] += c > d ? 3 : c == d ? 1 : 0;
    p[b - 1] += d > c ? 3 : c == d ? 1 : 0;
  }

  REP(i,n) ans[-p[i]]++;

  int cnt = 1;
  FOR(it, ans){
    REP(i,n) if(-p[i] == it->first)
      res[i] = cnt;
    cnt += it->second;
  }

  REP(i,n) printf("%d\n", res[i]);

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

using mint = modint998244353;

// セグメント木のデータ。0/1/転倒数を保存
struct S { ll zero, one, inv; };
S op(S l, S r) {
    ll zero = l.zero + r.zero;
    ll one = l.one + r.one;
    ll inv = l.inv + r.inv + l.one * r.zero;
    return S{zero, one, inv};
}
// 単位元。queryの範囲外の時に返す値
S e() { return {0, 0, 0}; }
// データに対する作用（写像）。遅延伝播させる値。swapするかしないか
using F = bool;
// 遅延評価時にdataを更新。dataに対してlazyを作用する
// 0/1をswap,新しいinvはone*zero-invとなる。00,11,01,11の各組み合わせの数の変化から計算する
S mapping(F f, S s) {
    if(!f) return s;
    else return {s.one, s.zero, s.one * s.zero - s.inv};
}
// g->fの順に作用する。lazy同士でlazyを更新する時に使う
// fとgの片方だけtrueだとtrue。XORで良い
F composition(F f, F g) { return f ^ g; }
// Fの単位元。何もしない時=false
F id() { return false; }

void solve() {
    ll n, q;
    cin >> n >> q;
    bool debug = false;
    vector<S> a(n);
    rep(i, n) {
        ll _a;
        cin >> _a;
        if(_a == 1) a[i] = S{0, 1, 0};
        else a[i] = S{1, 0, 0};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    if(debug) {
        rep(i, n) cout << seg.prod(i, i + 1).one << ' ';
        cout << endl;
    }
    while(q--) {
        ll t, l, r;
        cin >> t >> l >> r;
        --l, --r;
        if(t == 1) {
            seg.apply(l, r + 1, true);
            if(debug) {
                cout << "inverse: ["<< l << ", " << r << "]" << endl;
                rep(i, n) cout << seg.prod(i, i + 1).one << ' ';
                cout << endl;
            }
        }
        else {
            if(debug) {
                cout << "count: ["<< l << ", " << r << "]" << endl;
            }
            cout << seg.prod(l, r + 1).inv << endl;
        }
    }
    return;
}

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

Measured memory_bytes: 20368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    string s;int q;cin>>s>>q;
    deque<char> d;
    for(auto i = s.begin();i!=s.end();++i)d.push_back(*i);
    int t,f;
    int rcnt=0;
    char c;
    rep(i,q){
        cin>>t;
        if(t==1){rcnt++;}
        else{
            cin>>f>>c;
            if(f==1){if(rcnt%2==0)d.push_front(c);else d.push_back(c);}
            else{if(rcnt%2==0)d.push_back(c);else d.push_front(c);}
        }
        
    }
    if(rcnt%2==1)reverse(d.begin(), d.end());
    for(auto i = d.begin();i!=d.end();++i){
        cout<<*i;
    }
    printf("\n");
}

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

int main()
{
  int k, x;
  cin >> k >> x;
  int first = x-k+1;
  int last = x+k-1;
  cout << first;
  for (int i = first+1; i <= last; i++) {
    cout << ' ' << i;
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,j,k=0,l;
	char A[100],B[100];
	scanf("%s",&A);
	scanf("%s",&B);
	for(i=0;i<=2;i++)
	{
		if(A[i]==B[i])
		{
			k++;
		}
	}
	printf("%d",k);
}

Measured memory_bytes: 128
import sys
s = int(input())
if not ( 1 <= s <= 100 ): sys.exit()
array = [s]

for I in range(1,10 ** 6 + 1):
    if array[ I - 1 ] % 2 == 0:
        if array[I - 1]//2 in array:
            print(I + 1)
            sys.exit()
        array.append(array[(I - 1)]//2)     
    else:
        if (3 * array[I - 1]) + 1 in array:
            print(I + 1)
            sys.exit()
        array.append((3 * array[(I - 1)]) + 1)


Measured memory_bytes: 9204
#include <iostream>
#include <string>
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <cctype>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	int ans = 1;
	for(int i=0;i<n;i++){
		cin >> p.at(i);
	}
	int m = p.at(0);
	for(int i=1;i<n;i++){
		if(m > p.at(i)){
			ans++;
			m = p.at(i);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4032
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
ll in(){ ll x; cin >> x; return x; }
vector<ll> in(size_t n){ vector<ll> v(n); each(x, v) cin >> x; return v; }
/* }}} */

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



Measured memory_bytes: 256
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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


def trigcd(a,b,c):
    return gcd(gcd(a,b),c)


def main():
    K = int(input())

    res = 0

    for i in range(1,K+1):
        for j in range(i,K+1):
            for k in range(j,K+1):
                if (i == j) & (j == k):
                    same = 1
                elif (i == j) | (j == k) | (k == i):
                    same = 3
                else:
                    same = 6
                res += trigcd(i,j,k) * same

    print(res)



main()


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin>>a>>b;
 
  if(a==b) cout<<"Draw"<<endl;
  else if(a==1) cout<<"Alice"<<endl;
  else if(b==1) cout<<"Bob"<<endl;
  else cout<<(a<b? "Bob":"Alice")<<endl;
  return 0;
}

Measured memory_bytes: 384
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line;
int count[]=new int[101];
int max=0;
while((line=br.readLine())!=null){
count[Integer.parseInt(line)]++;
}
for(int i=1;i<=100;i++){
max=Math.max(max,count[i]);
}
for(int i=0;i<=100;i++){
if(count[i]==max){
System.out.println(i);
}
}
}
}

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

const int MAX_X = 1002;
bool b[MAX_X+1];

void isExp(int X) {
	b[1] = true;

	for (int i = 2; i <= X; i++)
		for (int j = i*i; j <= MAX_X; j *= i) {
			b[j] = true;
		}
}

int main() {
	int X;
	cin >> X;
	isExp(X);
	for (int i = X; i >= 1; i--)
		if (b[i]) {
			cout << i << endl;
			break;
		}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
        cout.tie(0);
	ll n;
	cin>>n;
	ll cnt1=0;
	ll cnt2=0,cnt3=0,cnt4=0;
	for(int i=0;i<n;i++)
	{
		string str;
		cin>>str;
		if(str=="AC")
		cnt1++;
		else if(str=="WA")
		cnt2++;
		else if(str=="TLE")
		cnt3++;
		else
		cnt4++;
	}
	cout<<"AC x "<<cnt1<<endl;
	cout<<"WA x "<<cnt2<<endl;
	cout<<"TLE x "<<cnt3<<endl;
	cout<<"RE x "<<cnt4<<endl;
}

Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int bin(int l, int r, ll key, ll b[]) {
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (b[m] >= key) r = m;
        else l = m;
    }
    return l;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll 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, a + n);
    sort(b, b + n);
    sort(c, c + n);
    bool flg[n];
    rep(i, n) if (b[0] >= c[i]) flg[i] = 1; else flg[i] = 0;
    bool flg2[n];
    rep(i, n) if (a[0] >= b[i]) flg2[i] = 1; else flg2[i] = 0;
    ll s = 0;
    rep(i, n) { //c
        c[i] = bin(0, n, c[i], b);
    }
    rep(i, n) { //b
        if (flg2[i] == 1) {b[i] = 0; continue;}
        b[i] = bin(0, n, b[i], a) + 1;
        
    }
    rrep(i, 1, n) {
        b[i] += b[i - 1];
    }
    rep(i, n) {
        if (flg[i] == 1) continue;
        s += b[c[i]];
    }
    cout << s << endl;
}




Measured memory_bytes: 2816
#include <stdio.h>

int main(){
  int n, ans;
  while(scanf("%d", &n) != EOF){
    ans = n % 39;
    ans = ans == 0 ? 39 : ans;
    printf(ans / 10 == 0 ? "3C0%d\n":"3C%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
long long n, a[(1<<20)], ans;
int main () {
    cin >> n;
    for ( int i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
        ans += a[i]/2;
        //a[i] %= 2;
    }

    for ( int i = 0 ; i < n ; ) {
        int j = i, cnt1 = 0;
        for ( ; j < n && a[j] ; j ++ ) {
            if ( a[j]%2 ) { cnt1 ++; }
        }
        ans += cnt1/2;
        if ( i == j ) { i ++ ; }
        else { i = j; }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(readline().split(), dtype=np.int32)
b = np.array(readline().split(), dtype=np.int32)
c = - np.array(readline().split(), dtype=np.int32)

a.sort()
b.sort()
c.sort()

cnt_a = np.searchsorted(a, b, side='left')
cnt_c = np.searchsorted(c, -b, side='left')
 
answer = (cnt_a * cnt_c).sum()
print(answer)


Measured memory_bytes: 20048
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {


	
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		
		long n = Long.parseLong(br.readLine());
		
		long res = (n)*(n-1)/2l;
		
		out.println(res);
		
		
		out.flush();
		out.close();
	}
	
	
	


}


Measured memory_bytes: 22484
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((lli)(n));i++)
#define reg(i,a,b) for(int i = ((lli)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((lli)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((lli)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	lli n, a;
	lli ans = 0;
	cin >> n >> a;
	vector<lli> x(n);
	rep(i, n){
		scanf("%lld", &x[i]);
		x[i] -= a;
	}
	sort(x.begin(), x.end());
	
	lli mi = 0, pl = n, z = 0, f = 0;
	rep(i, n){
		if(f == 0 && x[i] >= 0){
			mi = i; f = 1; i--;
		}else if(f == 1 && x[i] != 0){
			pl = i; break;
		}
	}
	if(x[n-1] < 0) mi = n;
	z = pl - mi;
	
	lli mim = 0, plm = 0;
	rep(i, mi) mim += x[i];
	reg(i, pl, n-1) plm += x[i];
	lli ma = min(-mim, plm);
	
	lli mia[ma+1], pla[ma+1];
	rep(i, ma) pla[i+1] = mia[i+1] = 0;
	mia[0] = 1; pla[0] = 1;
	
	for(int i = mi-1; i >= 0 ; i--){
		lli j = ma + x[i];
		for(; j>=0 ; j--){
			if(mia[j] != 0) mia[j-x[i]] += mia[j];
		}
	}
	
	for(int i = pl; i <= n-1 ; i++){
		lli j = ma - x[i];
		for(; j>=0 ; j--){
			if(pla[j] != 0) pla[j+x[i]] += pla[j];
		}
	}
	
	lli c = (1ll << z);
	
	rep(i, ma+1) if(mia[i] != 0 && pla[i] != 0){
		ans += (mia[i] * pla[i]);
	}
	
	cout << ans*c-1ll << endl;
	
	return 0;
}

Measured memory_bytes: 256