akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
const int nax = 1e5+103;
int n, k;
int dp[nax];
int a[nax];
int frog2(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int ans = abs(a[i]-a[i+1])+frog2(i+1);
	for(int j=2; j<=k; j++){
		if(i+j<n) ans = min(ans, abs(a[i]-a[i+j])+frog2(i+j));
	}
	return dp[i]=ans;
}
int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++) {cin>>a[i]; dp[i]=-1;}

	cout<<frog2(0)<<endl;
	return 0;
}


Measured memory_bytes: 5760
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////



int main(){fastio
    ll n,m;cin>>n>>m;
    string s;cin>>s;
    vector<ll>ans;
    ll pos=n;
    while(pos>0){
        bool flag=false;
        for(ll i=max(0,pos-m);i<=pos-1;i++){
            if(s[i]=='0'){
                ans.pb(pos-i);
                flag=true;
                pos=i;
                break;
            }
        }
        if(!flag){
            cout<<-1<<endl;return 0;
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto x:ans)cout<<x<<" ";
    
    return 0;
}


Measured memory_bytes: 1480
v500 = int(input())
v100 = int(input())
v50 = int(input())
sum = int(input())
count = 0
for i500 in range(v500 + 1):
    if 500 * (v500 - i500) <= sum:
        rest_500 = sum - 500 * (v500 - i500)
        for i100 in range(v100 + 1):
            if 100 * (v100 - i100) <= rest_500:
                rest_100 = rest_500 - 100 * (v100 - i100)
                for i50 in range(v50 + 1):
                    if 50 * (v50 - i50) == rest_100:
                        count += 1
print(count)


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

void swap(int* a,int* b)
{
 int tmp;
 tmp = *a;
 *a = *b;
 *b = tmp;
}
int main()
{
 int n;
 cin >> n;
 int nums[10000];
 int i;
 for(i=0;i<n;i++)
 {
  cin >> nums[i];
 }

 int j;
 int count = 0;
 int mini;
 for(i = 0;i<n;i++)
 {
  mini = i;
  for(j=i;j<n;j++)
  {
   if(nums[j]<nums[mini]){mini = j;}
  }
  if(mini!=i){swap(nums[i],nums[mini]);count++;}
 }
 
 cout << nums[0];
 for(i=1;i<n;i++)
 {
  cout << " " << nums[i];
 }
 cout << "\n" << count << endl;

}

Measured memory_bytes: 1172
n,m,l = [int(x) for x in input().split( )]
zeros1 = [[0 for x in range(m)] for y in range(n)]
zeros2 = [[0 for x in range(l)] for y in range(m)]
for i in range(n):
    retsu = [int(x) for x in input().split( )]
    zeros1[i] = retsu
for j in range(m):
    retsu2 = [int(x) for x in input().split( )]
    zeros2[j] = retsu2
answer = []
for i in range(n):
    mini_answer = []
    for j in range(l):
        value = 0
        for k in range(m):
            value += zeros1[i][k]*zeros2[k][j]
        mini_answer.append(value)
    answer.append(mini_answer)
for x in answer:
    print(*x)




Measured memory_bytes: 7052
//Bismillah_hir_rahmanir_rahim

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


int main()
{

    int n;
    cin>>n;

    if(n>=1 && n<=999)
    {
        printf("ABC\n");
    }
    else
    {
        printf("ABD\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main(void)
{
    int l;
    int m, n;
    
    while (1){
        scanf("%d", &l);
        if (l == 0) break;
        
        int money = 0;
        int ans = 0;
        bool flag = true;
        for (int i = 0; i < 12; i++){
            scanf("%d %d", &m, &n);
            money += (m - n);
            if ((l <= money) && (flag)) {
                ans = i + 1;
                flag = false;
            }
        }
        if (ans != 0){
            printf("%d\n", ans);
        }
        else {
            printf("NA\n");
        }
    }
    return (0);
}

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

int main (void){
    long long i,j;
    long long wa = 0; 
    long long n;
    long long a[105000] = {0};
    long long count=0;

    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    i=0;
    while(i<n){
        if(a[i] != a[i+1]){
            wa++;
            i++;
            count = 0;
        }else{
            count++;
            if(count % 2 == 1){
                wa--;
            }else{
                wa++;
            }
            i++;
        }
    }
   

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

    return 0;
}

Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define _ << " " <<
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

bool cmp(pair<string, int> a, pair<string, int> b) {
	if (a.first == b.first) return a.second > b.second;
	return a.first < b.first;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector <pair<string, int>> a(n);
	for (auto& i : a) cin >> i.first >> i.second;
	vector<pair<string, int>> b = a;
	sort(all(b), cmp);
	for (auto i : b) {
		for (int j = 0; j < n; j++) {
			if (a[j] == i) {
				cout << j + 1 << "\n";
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main() {

    string s;
    getline(cin, s);
    int length = static_cast<int>(s.size());
    int counter = 0;
    for (int i = 0; i < length; ++i) {
        if (counter == 0 && s[i] == 'C') {
            ++counter;
        }
        if (counter == 1 && s[i] == 'F') {
            ++counter;
        }
    }
    if (counter == 2) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 256
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
L = inl()

ans = 0
if len(L) >= 3:
    for i in range(len(L)):
        for j in range(i+1,len(L)):
            for k in range(j+1,len(L)):
                l_sum = L[i] + L[j] + L[k]
                if l_sum - max(L[i],L[j],L[k]) > max(L[i],L[j],L[k]) and L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
                    ans += 1

print(ans)

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define pb push_back
#define fastio ios::sync_with_stdio(false)
int main()
{
   fastio;
    lli n;
    cin>>n;
    
    lli cnt=0;
 
    lli v[10000020],a[2000020];
    for(lli i=1;i<=n;i++)
    cin>>a[i];
       sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        if(a[i]==a[i-1])
        v[a[i]]=1;
    }
    
    lli i,j;
    for( i=1;i<=n;i++)
    {
        if(!v[a[i]])
        {
            cnt++;
        }
        if(a[i]!=a[i-1])
        {for( j=2*a[i];j<1000001;j+=a[i])
        v[j]=1;}
    }
    cout<<cnt;
   
}
	

Measured memory_bytes: 13036
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < n; ++i)
#define fore(i, a, b) for(int i = a; i < b; ++i)

#define endl '\n'

const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> ar(n);
    for (int i = 0; i < n; ++i) {
        cin >> ar[i];
    }
    multiset<ll> st;
    for (int i = 0; i < n; ++i) {
        ll cur = 0;
        for (int j = i; j < n; ++j) {
            cur += ar[j];
            st.insert(cur);
        }
    }
    ll targ = 1ll << 40;
    ll ans = 0;
    while (targ) {
        int cnt = 0;
        for (const ll& v: st) {
            if (v & targ) cnt++;
        }
        if (cnt >= k) {
            ans += targ;
            auto it = st.begin();
            while (it != st.end()) {
                auto it2 = next(it);
                if ((*it & targ) == 0) st.erase(it);
                it = it2;
            }
        }
        targ >>= 1;
    }
    cout << ans << endl;
}

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

typedef struct{
	long double x;
	long double y;
}Coordinate;

void koch(int,Coordinate,Coordinate);
Coordinate Evaluate_u(Coordinate,Coordinate);
void print(Coordinate);

int main(){
	int n;
	cin>>n;
	Coordinate C_i,C_e;
	C_i.x = 0.0;C_i.y = 0.0;
	C_e.x = 100.0;C_e.y = 0.0;

	cout<<0.0<<" "<<0.0<<endl;
	koch(n,C_i,C_e);
	cout<<100.0<<" "<<0.0<<endl;

	cin.get();
	cin.get();
}

void koch(int d,Coordinate p1,Coordinate p2){
	if(d==0) return ;
	
	Coordinate s,t,u;
	s.x = (p1.x*2.0+p2.x*1.0)/3.0;
	s.y = (p1.y*2.0+p2.y*1.0)/3.0;
	t.x = (p1.x*1.0+p2.x*2.0)/3.0;
	t.y = (p1.y*1.0+p2.y*2.0)/3.0;
	u = Evaluate_u(s,t);
	
	koch(d-1,p1,s);
	print(s);
	koch(d-1,s,u);
	print(u);
	koch(d-1,u,t);
	print(t);
	koch(d-1,t,p2);
}

Coordinate Evaluate_u(Coordinate s,Coordinate t){
	Coordinate u;
	const double rad = 60.0*3.14159/180.0;
	u.x = (t.x-s.x)*cos(rad)-(t.y-s.y)*sin(rad)+s.x;
	u.y = (t.x-s.x)*sin(rad)+(t.y-s.y)*cos(rad)+s.y;
	return u;
}

void print(Coordinate c){
	cout<<c.x<<" "<<c.y<<endl;
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
using ll = long long;
using P = pair<int, int>;

struct Sieve
{
    int n;
    vector<int> f, primes;
    Sieve(int n = 1) : n(n), f(n + 1)
    {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i)
        {
            if (f[i])
                continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i)
            {
                if (!f[j])
                    f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x; }
    vector<int> factorList(int x)
    {
        vector<int> res;
        while (x != 1)
        {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x)
    {
        vector<int> fl = factorList(x);
        if (fl.size() == 0)
            return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl)
        {
            if (res.back().first == p)
            {
                res.back().second++;
            }
            else
            {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int choose2(int n)
{
    return n * (n - 1) / 2;
}

int main()
{
    int N, K;
    cin >> N;
    Sieve sieve(N);
    vector<int> factors(100);
    rep(i, N)
    {
        int n = i + 1;
        vector<pair<int, int>> factor = sieve.factor(n);
        rep(j, factor.size())
        {
            factors[factor[j].first] += factor[j].second;
        }
    }

    int ans = 0;
    int n2 = 0, n4 = 0, n14 = 0, n24 = 0, n74 = 0;
    rep(j, 100)
    {
        if (factors[j] >= 2)
            n2++;

        if (factors[j] >= 4)
            n4++;

        if (factors[j] >= 14)
            n14++;

        if (factors[j] >= 24)
            n24++;

        if (factors[j] >= 74)
            n74++;
    }
    ans += (n2 - 2) * choose2(n4);
    ans += (n2 - 1) * n24;
    ans += (n4 - 1) * n14;
    ans += n74;

    cout << ans << endl;
    return 0;
}

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

const int N = 101;
int n, W, arr[N], v[N];
map < long long , int > dp[N];

int call(int i, long long w)
{
    if(i == n)
        return 0;
    if(dp[i].find(w) != dp[i].end())
        return dp[i][w];
    int ret = call(i + 1, w);
    if(w + arr[i] <= W)
        ret = max(ret, v[i] + call(i + 1, w + arr[i]));
    return dp[i][w] = ret;
}

int main()
{
    cin>>n>>W;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        cin>>v[i];
        dp[i].clear();
    }
    printf("%d\n", call(0, 0));
    return 0;
}


Measured memory_bytes: 6272
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll D, G;
ll p[11], c[11];

int main() {
    fastio();
    cin >> D >> G;
    REP(i, D) cin >> p[i] >> c[i]; 
    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]) continue;
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n,a;
unordered_map<int,int> um;
int cnt;

int main() {
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        scanf("%d",&a);
        um[a]++;
    }

    for (auto& entry:um) {
        cnt+=entry.second-1;
    }

    int ans=um.size();
    if (cnt%2!=0) ans--;

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

Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;
int main(){
	ll N; cin >> N;

	vl cnt(26);
	FOR(i, 0, N) {
		char c; cin >> c;
		cnt[c - 'a'] ++;
	}
	ll ans = 1;
	FOR(i, 0, 26) {
		ans = (ans * (cnt[i]+1)) % MOD;
	}
	cout << (ans-1+MOD)%MOD << endl;
} //cin.tie(0) bei schnellem Wechseln



Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>

#include<atcoder/convolution>
#include<atcoder/dsu>
#include<atcoder/fenwicktree>
#include<atcoder/internal_bit>
#include<atcoder/internal_math>
#include<atcoder/internal_queue>
#include<atcoder/internal_scc>
#include<atcoder/internal_type_traits>
#include<atcoder/lazysegtree>
#include<atcoder/math>
#include<atcoder/maxflow>
#include<atcoder/mincostflow>
#include<atcoder/modint>
#include<atcoder/scc>
#include<atcoder/segtree>
#include<atcoder/string>
#include<atcoder/twosat>

using namespace std;
using namespace atcoder;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int t; cin>>t;
	while(t--){
		int n, m, a, b;
		cin>>n>>m>>a>>b;
		cout<<floor_sum(n,m,a,b)<<ln;
	}

	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

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

int main(){
    int n,k,ans = 1;
    cin >> n>> k;

    rep(i,0,n){
        if(i == 0)ans *= k;
        else ans *= k-1;
    }
    cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
function Main(input){
  //パラメータ受け取り
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var N = Number.parseInt(inputStr[0]);
  inputStr = input[1].split(" ");
  var H_arr = inputStr.map( inputStr => parseInt(inputStr));

  //解法として貪欲法を用いる
  var i = 0;	//今たっている場所
  var ans = []; //回答格納用配列
  //階段の0段目のコストをメモ。値は0
  ans.push(0);
  //階段の1段目に進んだ時のコストをメモ
  ans.push(Math.abs(H_arr[1]-H_arr[0]));
　//階段の3段目以降のコストをforループで処理を回して産出し続ける
  for( var i=2 ; i<N ; i++){
    var v1 = ans[i-1]+Math.abs(H_arr[i]-H_arr[i-1]);
    var v2 = ans[i-2]+Math.abs(H_arr[i]-H_arr[i-2]);
    ans.push(Math.min(v1,v2));
  }
  //結果表示
  console.log(ans[ans.length-1]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 27700
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    a = int(input())
    print(a + a * a + a * a * a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9164
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> a(4, 0), b(4, 0);

	while (cin >> a[0] >> a[1] >> a[2] >> a[3])
	{
		int hit = 0, blow = 0;
		rep(i, 4) { cin >> b[i]; }
		rep(i, 4)
		{
			if (a[i] == b[i]) { hit += 1; }
		}
		rep(i, 4)
		{
			blow += count(all(b), a[i]);
		}
		printf("%d %d\n", hit, blow - hit);
	}
	return 0;
}

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

ll gcd(ll a, ll b) {
    if (b == 0)return a;

    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    ll c=a*b;
    return c / gcd(a, b);
}

ll Doub(ll a){
  	if(a%2==1)return 0;
  	return(Doub(a/2))+1;
}

int main (){ 
    ll N, M;
    cin>>N>>M;
    vector<ll> A(N);
    ll LC=1;
  	ll Dou;
  	bool C=true;
    for(ll i=0; i<N; i++){
        cin>>A[i];
        A[i] /= 2;
        LC=lcm(LC, A[i]);
      	if(i==0)Dou=Doub(A[0]);
      	if(!(Dou==Doub(A[i]))){
          	C=false;
          	break;
        }
    }
    //cout<<LC<<endl;
  	ll Nu=M / LC;
  	if(Nu%2==1) Nu ++;
  	if(C){
      cout<< Nu / 2;
    }
  	else{
      	cout<<0;
    }
  	

}



Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int a[200000];

int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    int k=1;
    for(i=0;i<n;i++)
    {
        if(a[i]==k)
            k++;
    }
    k--;
    if(k==0)
        printf("-1");
    else
    printf("%d",n-k);
}


Measured memory_bytes: 896
#include <stdio.h>

int main(void){
	int a,i,n;
	int min = 1000000;
	int max = -1000000;
	long long int sum = 0;
	scanf("%d",&n);
	
	for(i = 0; i < n; i++){
		scanf("%d",&a);
		if(min > a) min = a;  //最小値
		if(max < a) max= a;  //最大値
		sum = sum + a;        //合計値
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;
 
#define MOD 1000000007
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> A(N);

    for(int i = 0; i < N; i++) cin >> A[i];

    vector<int> v;
    v.push_back(A[A.size() - 1]);

    for(int i = A.size() - 2; i >= 0; i--) {
        int a = A[i];
        if(a >= v[v.size() - 1]) {
            v.push_back(a);
        } else {
            int x = upper_bound(v.begin(), v.end(), a) - v.begin();
            v[x] = a;
        }
    }

    cout << v.size() << endl;
}

Measured memory_bytes: 4248
#include<cstdio>
inline int read(){
    int x=0;char ch=getchar();
    for(;ch<48||ch>57;ch=getchar());
    for(;ch>47&&ch<58;ch=getchar())
        x=(x<<1)+(x<<3)+(ch^48);
    return x;
}
using namespace std;
int main(){
    int a=read(),b=read(),c=read();
    if(a>=c)
        return printf("%d\n",b+c),0;
    if(a+b<c)
        return printf("%d\n",b+b+a+1),0;
    return printf("%d\n",b+c),0;
    return 0;
}


Measured memory_bytes: 128
//long long -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(long long i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<long long,long long>
#define vi vector<long long>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
long long,
null_type,
less<long long>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
long long solve()
{
	long long n,ans=0;cin>>n;
	vi v;
	REP(i,0,n-1)
	{
		long long a,b;
		cin>>a;cin>>b;
		ans-=b;
		v.pb(a+b);
	}
	sort(v.begin(),v.end(),greater<long long>());
	REP(i,0,n-1)
	{
		if(i%2==0){ans+=v[i];}
	}
	cout<<ans<<"\n";
}
signed main(){
	speed
	long long tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
using namespace std;
int main(){
	long long n;
	cin>>n;
	string a;
	while(n>0){
		n--;
		a+= char(int('a')+n%26);
		n/=26;
	}
	for(int i=a.size()-1;i<a.size();i--) cout<<a[i];
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

vector<vector<pair<ll, ll>>> graph;

vector<ll> ans;

// c: 0 か 1 か。v を c に塗る
void dfs(int v, int p, int c) {
  ans[v] = c;
  for (auto e : graph[v]) {
    if (e.first == p) {
      continue;
    }
    if (e.second & 1) {
      dfs(e.first, v, 1 - c);
    } else {
      dfs(e.first, v, c);
    }
  }
}
int main() {
  ll N;
  scanf("%lld", &N);
  graph.assign(N, vector<pair<ll, ll>>());

  for (ll i = 0; i < N - 1; i++) {
    ll u, v, w;
    scanf("%lld %lld %lld", &u, &v, &w);
    u--;
    v--;

    graph[u].emplace_back(make_pair(v, w));
    graph[v].emplace_back(make_pair(u, w));
  }

  ans.assign(N, 0);
  dfs(0, -1, 1);
  for (auto v : ans) {
    cout << v << endl;
  }
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N; ll C;
    cin >> N >> C;
    vector<vector<ll> > vX(2, vector<ll>(N + 1)), vV(2, vector<ll>(N + 1));
    for (int i = 1; i <= N; i++) { scanf("%ld %ld", &vX[0][i], &vV[0][i]); }
    // vX[0] = [0, C - x0, ..., C - x(N-1)]
    // vX[1] = [C - x0, ..., C - x(N-1), 0]
    for (int i = 1; i <= N; i++) {
        vX[1][i - 1] = C - vX[0][i];
        vV[1][i - 1] = vV[0][i];
    }
    // Vについて累積和
    // vV[0] = [0, v0, v0 + v1, ...]
    // vV[1] = [..., v(N-2) + v(N-1), v(N-1), 0]
    for (int i = 0; i < N; i++) {
        vV[0][i + 1] += vV[0][i];
        vV[1][N - (i + 1)] += vV[1][N - i];
    }
    // vMax[i][j] j番目までの最大ゲイン
    // vMax[0] : 0 ~ j
    // vMax[1] : N-1 - j ~ N-1
    vector<vector<ll> > vMax(2, vector<ll>(N + 1));
    for (int i = 1; i <= N; i++) {
        vMax[0][i] = max(vMax[0][i - 1], vV[0][i] - vX[0][i]);
        vMax[1][N - i] = max(vMax[1][N - (i - 1)], vV[1][N - i] - vX[1][N - i]);
    }

    ll ans = -LINF;
    // min(時計周り -> 反時計回り or 反時計周り -> 時計回り)
    for (int i = 0; i <= N; i++) {
        ans = max(ans, vV[0][i] - vX[0][i] * 2 + vMax[1][i]);
        ans = max(ans, vV[1][i] - vX[1][i] * 2 + vMax[0][i]);
    }
    cout << ans << '\n';
}

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

const long long HN = 1e18;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	long long ans = 1;
	bool hano = false;
	bool zr = false;
	for(int i=0;i<n;i++){
		long long x;
		cin>>x;
		if(x == 0){
			zr = true;
			ans = 0;
		}
		if(zr)continue;
		if(ans > HN/x){
			hano = true;
		}
		else ans *= x;
	}
	if(hano && !zr){
		cout<<-1;
	}else{
		cout<<ans;
	}
	
	return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] T = new int[N + 2];
		int[] A = new int[N + 2];
		for (int i = 1; i <= N; i++) {
			T[i] = sc.nextInt();
		}
		for (int i = 1; i <= N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();

		boolean wrong = false;
		int[] min = new int[N + 1];
		int[] max = new int[N + 1];

		for (int i = 1; i <= N; i++) {
			if (T[i] > T[i - 1]) {
				max[i] = T[i];
				min[i] = T[i];
			} else {
				max[i] = max[i - 1];
				min[i] = 1;
			}
		}
		for (int i = N; i >= 1; i--) {
			if (A[i] > A[i + 1]) {
				if (max[i] >= A[i] && A[i] >= min[i]) {
					max[i] = A[i];
					min[i] = A[i];
				} else {
					wrong = true;
					break;
				}
			} else {
				if (A[i] < min[i]) {
					wrong = true;
					break;
				} else {
					max[i] = Math.min(A[i], max[i]);
				}
			}
		}
		long ans = 1;
		long P = 1000000007;
		if (wrong == false) {
			for (int i = 1; i <= N; i++) {
				long a = max[i] - min[i] + 1;
				ans = (ans * a) % P;
			}
		} else {
			ans = 0;
		}
		System.out.println(ans);
	}
}


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

using namespace std;

using ll = long long;

bool judge(const string& s) {
    int n = s.size();
    for (int i = 0; i < n; ++i) {
        if (s[i] != s[n - 1 - i]) return false;
    }
    return true;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    cout << (judge(s) && judge(s.substr(0, (n - 1) / 2)) && judge(s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1)) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    
    int n, x;
    int num;
    while(cin>>n>>x&&!(n==0&&x==0)){
        num = 0;
        for(int i=1; i<=n-2; ++i){
            if(3*i>x){break;}
            else{
                for(int j=i+1; j<=n-1; ++j){
                    if(i+2*j>x){break;}
                    else{
                        for(int k=j+1; k<=n; ++k){
                            if(i+j+k==x){
                                ++num;
                                break;
                            }
                        }
                    }
                }
            }
        }
        cout << num << endl;
    }

    return 0;
    
}


Measured memory_bytes: 3088
#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;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

struct Grid {
  int y, x;

  Grid(int y, int x): y(y), x(x) {}

  bool operator < (const Grid& g) const {
    if (y != g.y) return y < g.y;
    else return (y & 1) ? x > g.x : x < g.x;
  }

  bool operator == (const Grid& g) const {
    return x == g.x && y == g.y;
  }

  bool operator != (const Grid& g) const {
    return x != g.x || y != g.y;
  }
};

struct Grid2 {
  int y, x, y2, x2;

  Grid2(int y, int x, int y2, int x2): y(y), x(x), y2(y2), x2(x2) {}
};

int main() {
  int h, w;
  cin >> h >> w;
  int a[h][w];
  rep(y, h) {
    rep(x, w) {
      cin >> a[y][x];
    }
  }

  vector<Grid> odd;
  rep(y, h) {
    rep(x, w) {
      if (a[y][x] & 1) odd.push_back(Grid(y, x));
    }
  }
  sort(odd.begin(), odd.end());
  int m = odd.size();

  vector<Grid2> ans;
  for (int i = 0; i + 1 < m; i += 2) {
    Grid g = odd[i];
    while (g != odd[i + 1]) {
      if (g.y & 1) {
        if (g.x == 0) {
          ans.push_back(Grid2(g.y, g.x, g.y + 1, g.x));
          g.y++;
        }
        else {
          ans.push_back(Grid2(g.y, g.x, g.y, g.x - 1));
          g.x--;
        }
      }
      else {
        if (g.x == w - 1) {
          ans.push_back(Grid2(g.y, g.x, g.y + 1, g.x));
          g.y++;
        }
        else {
          ans.push_back(Grid2(g.y, g.x, g.y, g.x + 1));
          g.x++;
        }
      }
    }
  }

  int n = ans.size();
  cout << n << endl;
  rep(i, n) {
    cout << ans[i].y + 1 << " " << ans[i].x + 1 << " " << ans[i].y2 + 1 << " " << ans[i].x2 + 1 << endl;
  }








  
  return 0;
}

Measured memory_bytes: 7152
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
int main ()
{
	int t,T;
	scanf("%d",&T);
    int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << A[T-1] << endl;
	
	return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    int h[n+1];
    int good=0;
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    vector<vector<int>> v(n+1);// vsize=
    while(m--){
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int count;
    for(int j=1;j<=v.size()-1;j++){
            int peak=h[j];
            count=0;
            for(int i=0;i<v[j].size();i++){
                if(peak>h[v[j][i]])
                    count++;
        }
            if(count==v[j].size())
                good++;
    }
    cout<<good<<endl;
    return 0;
}

Measured memory_bytes: 8780
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

ll n, p;
string s;

ll solve(){

    //cornercase
    if(p == 2 || p == 5){
        ll ans = 0;
        rep(i,n) if((s[n-i -1] - '0') %p == 0) ans += n-i; // 部分列の数分足す。
        return ans;
    }

    // p != 2 && p != 5
    
    vector<ll> cntmod(p, 0);
    ll tenfactor = 1;
    ll modp = 0;
    cntmod[0]++;

    rep(i,n){
        modp = (modp + (s[n-i-1]-'0') * tenfactor) %p;
        tenfactor = (tenfactor * 10) %p;
        cntmod[modp]++;
    }

    ll ans = 0;
    rep(i,p) ans += (cntmod[i] * (cntmod[i] - 1)) /2;

    return ans;
}


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

    dunk(solve());
}
    

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


public class Test
{	
    public static void Main()
	{
	    int[] a = new int[7] {1,3,5,7,8,10,12};
	    int[] b = new int[4] {4,6,9,11};
	    int[] c = new int[1] {1};
	    int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	    int x = nums[0];
	    int y = nums[1];
	    
	    if(a.Contains(x)) x = 111;
	    if(b.Contains(x)) x = 222;
        if(c.Contains(x)) x = 333;
        if(a.Contains(y)) y = 111;
	    if(b.Contains(y)) y = 222;
        if(c.Contains(y)) y = 333;
        
        if(x==y) Console.WriteLine("Yes");
        else Console.WriteLine("No");
	} 
}

Measured memory_bytes: 13396
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    a = int(readline())
    b = int(readline())
    h = int(readline())
    print((a+b)*h//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8980
import java.util.*;
import java.io.*;

public class Main {
    private static final int MAX_SIZE = 1000002;
    private static int key[]  = new int[MAX_SIZE];
    private static int prev[] = new int[MAX_SIZE];
    private static int next[] = new int[MAX_SIZE];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        init();

        int n = sc.nextInt();

        while (n-- > 0) {
            String cmd = sc.next();
            if (cmd.equals("insert"))
                insert(sc.nextInt());
            else if (cmd.equals("delete"))
                delete(sc.nextInt());
            else if (cmd.equals("deleteFirst"))
                deleteFirst();
            else
                deleteLast();
        }
        printKey();
    }
    private static void init() {
        for (int p = 1; p < next.length - 1; p++)
            next[p] = p + 1;
    }
    private static int newCell() {
        int p = next[1];
        next[1] = next[p];
        return p;
    }
    private static void putBack(int p) {
        next[p] = next[1];
        next[1] = p;
    }
    private static void destroy(int p) {
        prev[next[p]] = prev[p];
        next[prev[p]] = next[p];
        putBack(p);
    }
    private static void insert(int k) {
        int p = newCell();
        key[p] = k;
        prev[next[0]] = p;
        next[p] = next[0];
        next[0] = p;
        prev[p] = 0;
    }
    private static void delete(int k) {
        for (int p = next[0]; p != 0; p = next[p]) {
            if (key[p] == k) {
                destroy(p);
                break;
            }
        }
    }
    private static void deleteFirst() {
        destroy(next[0]);
    }
    private static void deleteLast() {
        destroy(prev[0]);
    }
    private static void printKey() {
        PrintWriter out = new PrintWriter(System.out);
        int first = next[0];
        for (int p = next[0]; p != 0; p = next[p]) {
            if (p != first)
                out.print(' ');
            out.print(key[p]);
        }
        out.println();
        out.flush();
    }
}



Measured memory_bytes: 459576
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int n,m;
ll x[1010],y[1010],z[1010];
ll calc(vector<bool> const& status){
  ll res=0;
  vector<ll> eat;
  rep(i,n){
    ll buf=0;
    if(status[0])buf+=x[i];
    else buf-=x[i];
    if(status[1])buf+=y[i];
    else buf-=y[i];
    if(status[2])buf+=z[i];
    else buf-=z[i];
    eat.push_back(buf);
    //else eat.push_back(0);
  }
  sort(ALL(eat));reverse(ALL(eat));
  rep(i,m){
    res+=eat[i];
  }
  return res;
}
ll solve(vector<bool> status,int cur){
  ll res=0;
  if(cur==4){
    return calc(status);
  }
  else{
    res=solve(status,cur+1);
    status[cur]=true;
    res=max(res,solve(status,cur+1));
  }
  return res;
}
signed main(){
  cin>>n>>m;
  rep(i,n){
    cin>>x[i]>>y[i]>>z[i];
  }
  vector<bool> status(4,false);
  ll res=solve(status,0);
  cout<<res<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int n;
string a[55];
int ap[55][30];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        for(int j=0;j<a[i].size();j++)
            ap[i][a[i][j]-'a']++;
    }
    for(int i=0;i<26;i++)
    {
        int kek=ap[1][i];
        for(int j=2;j<=n;j++)
            kek=min(kek,ap[j][i]);
        for(int j=1;j<=kek;j++)
            cout<<char(i+'a');
    }
    cout<<"\n";
    return 0;
}
/**

**/


Measured memory_bytes: 256
#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.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  

  int count = 0;
  for (int i = 0; i < N; i++)
  {
    if (i == 0) count++;
  	else if (a.at(i-1) != a.at(i)) count++;
  }
  	
  cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
const int MAX_N = 100000;
const int MAX_W = 10000;
typedef long long llong;

int n, k;
llong w[MAX_N];

int check(llong P) {
  int i = 0;
  for ( int j = 0; j < k; j++ ) {
    llong s = 0;
    while( s + w[i] <= P) {
      s += w[i];
      i++;
      if ( i == n ) return n;
    }
  }
  return i;
}

int solve() {
  llong left = 0;
  llong right = n * MAX_W;
  llong mid;
  while ( right - left > 1 ) {
    mid = (left + right) / 2;
    int v = check(mid);
    if ( v >= n ) right = mid;
    else left = mid;
  }
  return right;
}

int main() {
  scanf("%d %d", &n, &k);
  for ( int i = 0; i < n; i++ ) scanf("%lld", &w[i]);
  printf("%d\n", solve());
  return 0;
}


Measured memory_bytes: 3496
x,y=map(int,input().split())
mod=10**9+7
n_max=10**6+1
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod
a,b=2*y-x,2*x-y
if a<0 or b<0:
  print(0)
elif a%3!=0 or b%3!=0:
  print(0)
else:
  a//=3
  b//=3
  print(comb(a+b,a))


Measured memory_bytes: 56304
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

    vector<int> a;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }

    string ans = "YES";
    sort(a.begin(), a.end());

    for (int j = 0; j < n - 1; j++) {
        if (a[j] == a[j + 1]) {
            ans = "NO";
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 (b<a) { a=b; return 1; } return 0; }
#define int ll

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

    int n,k;cin>>n>>k;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    sort(ALL(h));reverse(ALL(h));
    int ans=0;
    for(int i=k;i<n;i++){
      ans+=h[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
for _ in[0]*int(input()):
 r=o=s=0
 while 1:
  a=input()[1]
  if'I'==a:
   if r<3:r+=1
   else:s+=1
  if'O'==a:s+=r+1;r=0
  if'U'==a:
   if o<2:o+=1
   else:print(s);break


Measured memory_bytes: 5596
#include <iostream>

using namespace std;

int func(int x){
  return x*x;
}

int main(void){

  int d;
  int sum;
  while( cin >> d ){
    sum = 0;
    for( int i = 0 ; i < 600/d ; i++ ){
      sum += func(i*d) * d;
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

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

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

int n,m,b[li],a[li],k,flag,t,visit[li],vis[li],cev1;
int cev;
char s[li];
vector<int> v;

main(void){
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=k;i++){
		int x;
		scanf("%lld %s",&x,s);
		if(s[0]=='A'){vis[x]=1;continue;}
		if(vis[x]==0)visit[x]++;
	}
	FOR{
		if(vis[i]==1)cev++;
		if(vis[i]==1)cev1+=visit[i];
	}
	printf("%lld %lld\n",cev,cev1);
	return 0;
}



Measured memory_bytes: 5120
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;
const double PI=3.14159265358979323846;


int main(){
  ll N,K,H,mx=0;
  cin>>N>>K;
  H=K;
  vector<ll> A;
  vector<ll> F;
  REP(i,N){
    ll a;
    cin>>a;
    A.push_back(a);
  }
  REP(i,N){
    ll a;
    cin>>a;
    F.push_back(a);
  }

  SORT(A);
  SORT(F);
  REVERSE(F);
  
  REP(i,N) mx=max(mx,A.at(i)*F.at(i));
  
  ll ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
  ll ok = 1000000000001; // 「index = N-1」が条件を満たさないこともあるので、初期値は N
  
  /* ok と ng のどちらが大きいかわからないことを考慮 */
  while (abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      
      K=H;
    
      for(ll i=0; i<N; ++i){
        if(A.at(i)*F.at(i)>mid) K-=A.at(i)-mid/F.at(i);
      }
    
      if (K>=0){
        ok = mid;
      }
    
      else ng = mid;
  }
  
  cout<<ok<<endl;
}

Measured memory_bytes: 4976
program making_palindrome
  implicit none
  integer(8), parameter :: inf = 1e18
  integer :: n, i
  character(20) :: s(50, 2) = ''
  integer(8) :: c(50) = 0, m(50, 21, 2) = 0, x = inf
  logical :: u(50, 21, 2) = .false.
  read(*,*) n
  do i = 1, n
    read(*,*) s(i, 1), c(i)
    s(i, 2) = reverse(s(i, 1)(1:len_trim(s(i, 1))))
  end do
  do i = 1, n
    x = min(x, solve(i, 1, 1) + c(i))
  end do
  write(*,'(i0)') merge(x, -1_8, x < inf)
contains
  function reverse(s) result(res)
    character(*), intent(in) :: s
    character(len_trim(s)) :: res
    integer :: n, i
    n = len_trim(s)
    do i = 1, n
      res(i:i) = s(n - i + 1:n - i + 1)
    end do
  end
  recursive integer(8) function solve(i, j, k) result(res)
    integer, intent(in) :: i, j, k
    integer :: l, r, t
    logical :: f
    res = m(i, j, k)
    if (u(i, j, k)) return
    u(i, j, k) = .true.
    m(i, j, k) = inf
    l = j
    r = len_trim(s(i, k))
    f = .true.
    do while (l < r)
      if (s(i, k)(l:l) /= s(i, k)(r:r)) then
        f = .false.
        exit
      end if
      l = l + 1
      r = r - 1
    end do
    if (f) then
      m(i, j, k) = 0
      res = 0
      return
    end if
    do t = 1, n
      l = j
      r = 1
      do while (l <= len_trim(s(i, k)) .and. r <= len_trim(s(t, 3 - k)))
        if (s(i, k)(l:l) /= s(t, 3 - k)(r:r)) exit
        l = l + 1
        r = r + 1
      end do
      if (l == len_trim(s(i, k)) + 1) then
        m(i, j, k) = min(m(i, j, k), solve(t, r, 3 - k) + c(t))
      end if
      if (r == len_trim(s(t, 3 - k)) + 1) then
        m(i, j, k) = min(m(i, j, k), solve(i, l, k) + c(t))
      end if
    end do
    res = m(i, j, k)
  end
end program making_palindrome

Measured memory_bytes: 2916