akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int chmax(ll a,ll b){//参照なので引数を指す。だが、
	if (a < b){
     a=b; 
	}
  return a;
}
//単なる値の場合はただのコピーで返り値を作れば良い
int chmin(ll a,ll b){
	if (a>b){
     a=b; 
	}
  return a;
}

int main(){
  //漸化式パターン、ナップサック問題に非常に似ている。
  int N;
  cin >>N;
  vector <int>v(N);
  for (int i=0;i<N;i++){
  cin >>v.at(i);
    //ジャンプ先のコストを配列に入れる。
  }
  vector <ll>dp(N);
  //dpテーブルを作成する。ここでdp(i)にはiに行くための最小コストを書けばよくね？よってi=0が１の足場になる。dp(N-1)は
  dp.at(0)=0;
  for (int i=2;i<N;i++){
  dp.at(i)=10000000000;//ここは後で変更する。初期化完了
  }

  dp.at(1)=dp.at(0)+chmax(v.at(1)-v.at(0),v.at(0)-v.at(1));
 
  for (int i=2;i<N;i++){
   dp.at(i)=chmin(dp.at(i),dp.at(i-1)+chmax(v.at(i)-v.at(i-1),v.at(i-1)-v.at(i)));
    dp.at(i)=chmin(dp.at(i),dp.at(i-2)+chmax(v.at(i)-v.at(i-2),v.at(i-2)-v.at(i)));
  }
  cout <<dp.at(N-1)<<endl;        
}
//この後はvoid関数についてreturn値なしでやってみる。

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
int n,m,t[100],p[100],x[100],ans[100]={0},all=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
    all=all+t[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>p[i]>>x[i];
    ans[i]=all-(t[p[i]-1]-x[i]);
    cout<<ans[i]<<endl;
  }
}

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

#define rep(i, n) for(int i = 0; i < n; i++ )

using namespace std;

int main(void){
    int K = 0;
    int N = 0;
    int max_range = 0;   // all_dist - max_range = answer 

    cin >> K >> N;
    vector<int> points(N);

    rep(i, N){
        cin >> points[i];
    } 
    points.push_back(points[0]+K);  // 1,2,...,N,1←一周分十分にとる 

    rep(i, N){
        max_range = max(max_range, points[i+1]-points[i]);
    }

    cout << K - max_range << endl;
    
    return 0;
}

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

int main () {
  int N, a, b, c, d;
  cin >> N;
  
  a = N/1000;
  b = (N-a*1000)/100;
  c = (N-a*1000-b*100)/10;
  d = N-a*1000-b*100-c*10;
  
  vector<int> data = {a,b,c,d};
  
  if (data.at(0)==data.at(1)&&data.at(1)==data.at(2)||
      data.at(1)==data.at(2)&&data.at(2)==data.at(3)||
      data.at(0)==data.at(1)&&data.at(1)==data.at(2)&&data.at(2)==data.at(3)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	string s;
	cin >> s;
	REP(i, s.length() - 1) if (s[i] == 'A' && s[i + 1] == 'C') {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}
 

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()
  l.sort()

  ans=0
  for i in range(k):
    ans+=l[i]
  return ans

# main()
print(main())


Measured memory_bytes: 10796
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
int main(){
  string t;
  cin>>t;
  ll n=t.size();
  if(n==1&&t[0]=='?'){
    cout<<'D'<<endl;
    return 0;
  }
else if(n==1&&t[0]!='?'){
     cout<<t<<endl;
     return 0;
   }
  rep(i,n){
    if(t[i]=='?') t[i]='D';
  }
  cout<<t<<endl;
return 0;
}

Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int dec = 0,inc = 0;
        //マス数
        int n = sc.nextInt();
        //料金所数
        int m = sc.nextInt();
        //初期位置
        int x = sc.nextInt();

        //料金所位置
        int a = 0;
        for(int i = 0;i < m;i++){
            a = sc.nextInt();
            if(a < x){
                dec++;
            }
            else{
                inc++;
            }
        }

        System.out.println(Math.min(dec,inc));
    }
}

Measured memory_bytes: 21716
N,M=map(int,input().split())
mod = 10**9+7
def fact_list(a):
  ans = [1]
  for i in range(1,a+1):
    ans.append(ans[-1]*i % mod)
  return ans

factlist = fact_list(M)

def comb_mod(a,b):
  return (factlist[a]*pow(factlist[b],mod-2,mod)*pow(factlist[a-b],mod-2,mod) )% mod

def permu_mod(a,b):
  return (factlist[a]*pow(factlist[a-b],mod-2,mod) % mod)

ans = 0
for i in range(N+1):
  ans += comb_mod(N,i)*(-1)**i*permu_mod(M,i)*permu_mod(M-i,N-i)**2 
  ans = ans % mod
print(ans)


Measured memory_bytes: 104032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
           int n;
           cin >>n;

    vector<int> vec(10005,0);
  int v=0;
  for(int i=1;i<=sqrt(n);i++){
  for(int j=1;j<=sqrt(n);j++){
  for(int k=1;k<=sqrt(n);k++){
    
v=j*(i+j+k)+k*(i+k)+i*i;
    if(v<=10000){vec[v]++;}
  
  }
  }
  }
 for(int i=1;i<=n;i++)cout<<vec[i]<<endl;



}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
typedef long long ll;
#define mod 924844033
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
int f[2010],fact[2010],ifact[2010];
int C(int n,int m){if(n<m)return 0;return 1ll*fact[n]*ifact[m]%mod*ifact[n-m]%mod;}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),K=gi();
	fact[0]=1;for(int i=1;i<=n;++i)fact[i]=1ll*fact[i-1]*i%mod;
	ifact[n]=pow(fact[n],mod-2);for(int i=n;i;--i)ifact[i-1]=1ll*ifact[i]*i%mod;
	f[0]=1;
	for(int l=1;l<=n&&l<=K*2;++l){
		int r=l;while(r+K*2<=n)r+=K*2;
		int cnt=(r-l)/K+(l>K)+(r+K<=n);
		for(int i=n;i;--i)
			for(int j=1;j*2-1<=cnt&&j<=i;++j)
				f[i]=(f[i]+1ll*f[i-j]*C(cnt-j+1,j))%mod;
	}
	int ans=0;
	for(int i=0,m=1;i<=n;++i,m=mod-m)ans=(ans+1ll*f[i]*m%mod*fact[n-i])%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
import Data.Maybe
import Data.List
import qualified Data.Set as H
import qualified Data.IntMap as M
import qualified Data.IntSet as S
import qualified Data.ByteString.Char8 as B

type Index = Int
data Edge = Edge { cost :: Int, src :: Index, dst :: Index } deriving (Show, Eq, Ord)
type Edges = M.IntMap [Edge]
type Node = (Int, Index)

makeEdges :: [Node] -> [Edge]
makeEdges l = [edge | edge@(Edge _ src dst) <- edges', src >= 0 && dst >= 0]
  where
    f (z, (c, i)) (c', j) =
      let cost = c' - c
      in (Edge cost i j : Edge cost j i : z, (c', j))
    (edges', _) = foldl' f ([], (0, -1)) l

upsert :: Edges -> Edge -> Edges
upsert edges edge@(Edge _ src _)
  | M.member src edges = M.update (\curr -> Just (edge : curr)) src edges
  | otherwise = M.insert src [edge] edges

type PQ = H.Set Edge
mst' :: Int -> PQ -> S.IntSet -> Int -> Edges -> Int
mst' total pq visited n edges
  | dst == (-1) = total
  | S.member dst visited = mst' total poped visited n edges
  | otherwise =
      let
          total' = total + cost
          visited' = S.insert dst visited
          nexts = filter (\(Edge _ _ dst') -> S.notMember dst' visited') $ fromJust $ M.lookup dst edges
          pq' = foldl' (flip H.insert) poped nexts
      in mst' total' pq' visited' n edges
  where
    edge@(Edge cost _ dst) = if H.null pq
                             then Edge (-1) (-1) (-1)
                             else H.elemAt 0 pq
    poped = H.deleteAt 0 pq


mst :: Int -> Edges -> Int
mst n edges = mst' 0 pq visited n edges
  where
    edge = fromJust $ M.lookup 0 edges
    pq = H.fromList edge
    visited = S.fromList [0]

solve :: [(Int, Int)] -> Int
solve l = mst n edges
  where
    n = length l
    xs = makeEdges $ sort $ zip (map fst l) [0..]
    ys = makeEdges $ sort $ zip (map snd l) [0..]
    dummy = Edge (-1) (-1) (-1)
    edges = foldl' upsert (M.fromList [(-1,[dummy])]) (xs ++ ys)

toTuple :: [Int] -> (Int, Int)
toTuple [x,y] = (x,y)

readInt = fst . fromJust . B.readInt
main = B.getContents >>= print . solve . map (toTuple . map readInt . B.words) . tail . B.lines


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
int N, K, Q;
	cin >> N >> K >> Q;
	map<int, int> A;
	fx(Q) {
		int a;
		cin >> a;
		A[a]++;
	}
	fx(N) {
		if (K-Q+A[x+1]>0) {
			ce("Yes")
		}
		else {
			ce("No")
		}
	}
    return 0;
}



Measured memory_bytes: 5376
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


bool isLeapYear( int yy ) {
    return yy % 3 == 0;
}

int solve( int yy, int mm, int dd ) {
    int res = 0;
    for ( int y = yy; y < 1000; ++ y ) {
        for ( int m = ( y == yy ? mm : 1 ); m <= 10; ++ m ) {
            int days = ( m % 2 == 1 ? 20 : 19 );
            if ( isLeapYear( y ) ) days = 20;
            for ( int d = ( y == yy && m == mm ? dd : 1 ); d <= days; ++ d ) {
                res ++;
            }
        }
    }
    return res;
}

int main() {
    int n;
    while ( cin >> n ) {
        int yy, mm, dd;
        for ( int i = 0; i < n; ++ i ) {
            cin >> yy >> mm >> dd;
            cout << solve( yy, mm, dd ) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    string str;
    cin >> str;

    long i = 0;
    char c = 'J';
    int res = 0;

    while(i < str.length()) {
        int levelj = 0;
        int levelo = 0;
        int leveli = 0;

        while(str[i] == 'J') {
            levelj += 1;
            i += 1;
        }
        while(str[i] == 'O') {
            levelo += 1;
            i += 1;
        }
        while(str[i] == 'I') {
            leveli += 1;
            i += 1;
        }
        if (0 < levelo && levelo <= levelj && levelo <= leveli) {
            res = max(res, levelo);
        }

    }

    cout << res << endl;
     
    return 0;
}

Measured memory_bytes: 1960
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define NMAX 200
#define MOD 666013
#define INF 1e9
#define f cin
using namespace std;


//ifstream f("date.in");

vector<pair<int, int> > a[100];
int n;
int v_max;
int v[100];

void verif() {

    int nr1 = 0;
    for (int i = 0; i < n; ++i) {
        if (v[i] == 0) continue;
        nr1 ++;
        for (int j = 0; j < a[i].size(); ++j) {
            int neigh = a[i][j].first;
            int val = a[i][j].second;
            if (v[neigh] != val) return;
        }
    }

    v_max = max(v_max, nr1);

}

void bk(int k) {
    for (int i = 0; i < 2; ++i) {
        v[k] = i;
        if (k == n - 1) {
            verif();
        } else bk(k + 1);
    }
}

int main() {

    f >> n;
    for (int i = 0; i < n; ++i) {
        int nr;
        f >> nr;
        for (int j = 0; j < nr; ++j) {
            int x, y;
            f >> x >> y;
            x --;
            a[i].push_back(make_pair(x, y));
        }
    }

    bk(0);

    cout << v_max;

    return 0;
}


Measured memory_bytes: 256
n = $stdin.gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
ans = 0
n.times do |k|
  if (k+1) % 2 == 1
    if arr[k] % 2 == 1
      ans += 1
    end
  end
end
puts ans

Measured memory_bytes: 14300
#include <bits/stdc++.h>
using namespace std;int n,m,q,a[50],b[50],c[50],d[50],o,p[10];void u(int l,int f){if(l==n){int s=0;for(int i=0;i<q;i++)if(p[b[i]-1]-p[a[i]-1]==c[i])s+=d[i];o=max(o,s);return;}for(int i=f;i<=m;i++){p[l]=i;u(l+1,i);}}int main(){cin>>n>>m>>q;for(int i=0;i<q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];u(0,1);cout<<o;}


Measured memory_bytes: 3588
#include <iostream>
#include <iterator>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
typedef long long ll;

long long gcd(long long a, long long b)
{
  while(b) {
    long long at = a;
    a = b;
    b = at % b;
  }
  return a;
}

long long lcm(long long a, long long b)
{
  if (b > a) swap(a, b);
  return a / gcd(a, b) * b;
}

int main()
{
  int N;
  cin >> N;
  vector<ll> T(N);
  for_each(T.begin(), T.end(), [](ll& e) { cin >> e; });
  cout << accumulate(T.begin(), T.end(), 1LL, [](ll acc, ll& e) { return lcm(acc, e); }) << endl;
  return 0;
}


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

int main(){
    int n, a, b; cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int tmp = i;
        int sum = 0;
        while(tmp > 0){
            sum += tmp % 10;
            tmp /= 10;
        }
        if(a<=sum && sum<=b) ans+=i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    string ans;
    
    int b1 = 0, b2 = 0, b4 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] % 2) ++b1;
        else {
            int tmp = a[i];
            int cnt = 0;
            while (tmp % 2 == 0) {
                ++cnt;
                tmp /= 2;
            }
            if (cnt == 1) ++b2;
            else ++b4;
        }
    }

    if (b2) {
        if (b1 <= b4) ans = "Yes";
        else ans = "No";
    } else {
        if (b1 <= b4+1) ans = "Yes";
        else ans = "No";
    }

    cout << ans << endl;

    return 0;
}



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

typedef long long ll;
#define RE register
#define clear(a) memset(a,0,sizeof a)

inline int read(){
    int date=0,w=1;char c=0;
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
    return date*w;
}

void chkmin(int &x,int y){
	x=min(x,y);
}
void chkmax(int &x,int y){
	x=max(x,y);
}
int n,ans,a[1000005];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=2*n;++i)cin>>a[i];
    sort(a+1,a+2*n+1);
    for(int i=1;i<=n;++i){
    	ans+=a[i*2-1];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
for j in range(min(K,50)):
	B = [0]*N
	for i in range(N):
		l = max(0,i-A[i])
		r = min(N-1,i+A[i])
		B[l] += 1
		if r < N-1:
			B[r+1] -= 1
	for i in range(1,N):
		B[i] += B[i-1]
	A = B
print(' '.join(map(str,A)))


Measured memory_bytes: 169812
import math
a,b,x=map(int,input().split())
w=2*x/(a*b)
if w==0:
  print(0)
elif w<=a:
  print(math.degrees(math.atan(b/w)))
else:
  u=2*x/(a**2)-b
  print(math.degrees(math.atan((b-u)/a)))

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn abc(x_1:i32, y_1:i32, x_2:i32, y_2:i32) {
    let diff_x = x_2 - x_1;
    let diff_y = y_2 - y_1;

    let x_3 = x_2 - diff_y;
    let y_3 = y_2 + diff_x;
    let x_4 = x_1 - diff_y;
    let y_4 = y_1 + diff_x;

    println!("{} {} {} {}", x_3, y_3, x_4, y_4)
}

fn main() {

    input!{
        x_1: i32,
        y_1: i32,
        x_2: i32,
        y_2: i32,
    }
    abc(x_1, y_1, x_2, y_2)
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll N, K;
const ll mod = 1e9 + 7;
bool used[100010];
vector<int> G[100010];

class prm{
private:
    ll MAX_N;
    ll mod;
    vector<ll> prmt;
public:

    ll exp(ll x, ll y){
        if(y == 0) return 1;

        ll x2 = exp(x, y / 2) % mod;
        x2 = x2 * x2 % mod;
        
        if(y % 2 == 1) x2 = x2 * x % mod;

        return x2;
    }

    prm(ll n = 0, ll m = 0){
        MAX_N = n;
        mod = m;
        prmt.resize(MAX_N + 1);

        vector<ll> fct;
        
        fct.push_back(1);
        fct.resize(MAX_N + 1);
        
        for(ll i = 1; i <= MAX_N; i++){
            fct[i] = fct[i - 1] * i % mod;
        }
        for(int i = 0; i <= MAX_N; i++){
            prmt[i] = fct[MAX_N];
            prmt[i] = exp(fct[MAX_N - i], mod - 2) * prmt[i] % mod;
        }
    }

    ll res(int r){
        return prmt[r];
    }
};

int main(){

    cin >> N >> K;
    if(N == 1){
        cout << K << endl;
        return 0;
    }

    prm p1(K - 2, mod);

    for(int i = 1; i < N; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> node;
    node.push(1);
    used[1] = true;
    
    ll ans = K * (K - 1) % mod;

    while(!node.empty()){

        int n = node.front();
        node.pop();

        if(G[n].size() + 1 > K){
            ans = 0;
            break;
        }

        int cnt = -1;
        for(auto& u : G[n]){
            cnt++;
            if(used[u]) continue;
            used[u] = true;
            node.push(u);
        }

        ans = ans * p1.res(cnt) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7408
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define PB push_back
vvint vv;
int dp[1<<10][1<<10];
inline int saiki(int a,int b,int c){
	if(dp[a][b]>=0) return dp[a][b];
	dp[a][b]=2;
	for(int y:vv[a]){
		if(y==c) return dp[a][b]=1;
		if(y+b!=(y|b)) continue;
		if(saiki(y,y|b,c)==1) return dp[a][b]=1;
	}
	return 2;
}
int main(){
	int n;
	while(cin>>n,n){
		string s;
		cin>>s;
		vv=vvint(1<<10);
		rep(i,1<<10) rep(j,1<<10) dp[i][j]=-1;
		int state=0;
		vvint ww(1<<10);
		bool ans=false;
		rep(i,s.size()){
			if(s[i]=='u'){
				state=0;
				continue;
			}
			int t=s[i]-'0';
			if(state&(1<<t)) ans=true;
			if(s[i+1]=='u') continue;
			state|=1<<t;
			ww[state].PB(s[i+1]-'0');
		}
		rep(i,1<<10){
			for(int x:ww[i]){
				rep(j,1<<10){
					if(i==j) continue;
					if(!(j&(1<<x))) continue;
					if(i+j!=(i|j)) continue;
					vv[i].PB(j);
				}
			}
		}
		rep(i,1<<10){
			if(ww[i].size()==0) continue;
			if(saiki(i,i,i)==1) ans=true;
		}
		puts(ans?"UNSAFE":"SAFE");
	}
}

Measured memory_bytes: 11184
#include<stdio.h>
int main(){
    int n,m,i[101],j,b,a[1000][101],ans[1000]={},ai,ue,oka;
    scanf("%d %d",&n,&m);
    for(ai=0;ai<n;ai++){
        for(ue=0;ue<m;ue++){
            scanf("%d",&a[ai][ue]);
        }
    }
    for(oka=0;oka<m;oka++){
        scanf("%d",&i[oka]);
    }
    for(ai=0;ai<n;ai++){
        for(ue=0;ue<m;ue++){
            ans[ai]+=i[ue]*a[ai][ue];
        }
    }
     
    for(oka=0;oka<n;oka++){
        printf("%d\n",ans[oka]);
    }
     
     
     
     
     
     
     
    return 0;
}


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

int main(void){
    int i,ex1,ex2,ex3,ex4,a,b;
    int dice[7],dice2[7];
    int command;

    for(i = 1;i <= 6;i++){
        scanf("%d",&dice[i]);
    }

    for(i = 1;i <= 6;i++){
        scanf("%d",&dice2[i]);
    }

    for(i = 0;i < 10000;i++){
            command = rand() % 4;
            if(command == 0){
                ex1 = dice[1];
                ex2 = dice[2];
                ex3 = dice[5];
                ex4 = dice[6];
                dice[1] = ex3;
                dice[2] = ex1;
                dice[5] = ex4;
                dice[6] = ex2;
            }else if(command == 1){
                ex1 = dice[1];
                ex2 = dice[2];
                ex3 = dice[5];
                ex4 = dice[6];
                dice[1] = ex2;
                dice[2] = ex4;
                dice[5] = ex1;
                dice[6] = ex3;
            }else if(command == 2){
                ex1 = dice[1];
                ex2 = dice[3];
                ex3 = dice[4];
                ex4 = dice[6];
                dice[1] = ex3;
                dice[3] = ex1;
                dice[4] = ex4;
                dice[6] = ex2;
            }else if(command == 3){
                ex1 = dice[1];
                ex2 = dice[3];
                ex3 = dice[4];
                ex4 = dice[6];
                dice[1] = ex2;
                dice[3] = ex4;
                dice[4] = ex1;
                dice[6] = ex3;
            }
            for(a = 1;a <= 6;a++)
                if(dice[a] != dice2[a])
                    break;
            if(a == 7){
                printf("Yes\n");return 0;
            }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

#define MAX_V 1000

struct Edge{ int to; LL cap,rev; };
int used[MAX_V];
vector<Edge> G[MAX_V];

void addEdge(int from,int to,LL cap){
    G[from].push_back((Edge){to,cap,(int)G[to].size()});
    G[to].push_back((Edge){from,0,(int)G[from].size()-1});
}

LL DFS(int v,int t,LL f){
    if(v==t)
        return f;
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
        Edge &e=G[v][i];
        if(!used[e.to] && 0<e.cap){
            int d=DFS(e.to,t,min(f,e.cap));
            if(0<d){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
LL maxFlow(int s,int t){
    LL flow=0;
    while(1){
        for(int i=0;i<MAX_V;i++)
            used[i]=false;
        LL f=DFS(s,t,LLMAX/10);
        if(f==0)
            break;
        flow+=f;
    }
    return flow;
}

int N;
int a[1000];

int main(void){
    scanf("%d",&N);
    LL offset=0;
    FOR(i,1,N+1){
        scanf("%d",a+i);
        if(0<=a[i]){
            offset+=a[i];
            addEdge(0,i,a[i]);
            addEdge(i,N+1,0);
        }else{
            addEdge(0,i,0);
            addEdge(i,N+1,-a[i]);
        }
        for(int j=2;j*i<=N;j++){
            addEdge(j*i,i,LLMAX/10);
        }
    }
    LL ans=offset-maxFlow(0,N+1);
    // printf("ans=%lld\n",ans);
    // printf("maxFlow=%lld\n",maxFlow(0,N+1));
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	
	ll x;
	cin>>x;
	ll curr=1;
	ll init=100;
	while(1)
	{
		ll zz=(init)/100;
		init+=zz;
		if(init>=x)
			break;

		curr++;
	}
	cout<<curr;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; cin >> s;
  int k; cin >> k;
  int now = 0, sz = s.size();
  vector<string> vec;
  REP(i, 26) {
    char c = 'a' + i;
    set<pair<int, int>> st;
    REP(j, sz) if (s[j] == c) {
      if (j == sz-1) st.insert({-1, j});
      else st.insert({s[j+1]-'a', j});
    }
    for (auto a : st) FOR(j, 1, min(sz-a.second, k)+1) vec.push_back(s.substr(a.second, j));
    sort(ALL(vec));
    vec.erase(unique(ALL(vec)), vec.end());
    if (vec.size() >= k) {
      cout << vec[k-1] << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 1916
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define MN 101000

int a[MN], b[MN];
int c[MN], d[MN];
int s = 0, s2 = 0;
bool vis[MN];
std::vector<int> v[MN];
bool ok = 1;
int ans = 0, now = 0;

void dfs(int x)
{
	if(vis[x]) return; 
	vis[x] = 1;
	now += v[x].size();
	if(c[x] == s) ok = 0;
	for(auto &y : v[x]) dfs(y);
}

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), s ^= a[i], c[i] = a[i];
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]), s2 ^= b[i], d[i] = b[i];
	c[n + 1] = s; d[n + 1] = s2;
	std::sort(c + 1, c + n + 2);
	std::sort(d + 1, d + n + 2);
	for(int i = 1; i <= n + 1; i++) if(c[i] != d[i]) return 0 * puts("-1");
	int N = std::unique(c + 1, c + n + 2) - c - 1;
	for(int i = 1; i <= n; i++)
	{
		int A = std::lower_bound(c + 1, c + N + 1, a[i]) - c;
		int B = std::lower_bound(c + 1, c + N + 1, b[i]) - c;
		if(A != B) v[A].push_back(B), v[B].push_back(A);
	}
	for(int i = 1; i <= N; i++)
		if(!vis[i]) 
		{
			now = 0; ok = 1;
			dfs(i);
			if(now) ans += now / 2 + ok;
		}
	printf("%d\n", ans);
}

Measured memory_bytes: 10496
using System;
class Program {
  static void Main(string[] args) {
    int N = int.Parse(Console.ReadLine());

    int[] A = new int[N];
    int total = 0;
    string[] values = Console.ReadLine().Split();
    for (int i = 0; i < N; ++i) {
      A[i] = int.Parse(values[i]);
      total += A[i];
    }

    Array.Sort(A, (a,b) => b - a);

    int sum = 0;
    for (int i = 0; i < N; i += 2) {
      sum += A[i];
    }

    Console.WriteLine(sum * 2 - total);
  }
}


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

int main()
{
    string s;
    int ans = 0;
    cin >> s;
    if (s[2]==s[3]&&s[4]==s[5]) {
        cout << "Yes"<<endl;
    } else {
        cout << "No"<<endl;

    }
    return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int ans = true;
  rep(i, n) {
    if (a[i] % 2 == 0) {
      if (a[i] % 3 == 0 || a[i] % 5 == 0) {
      } else {
        ans = false;
        break;
      }
    }
  }
  if (ans)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
$ans=(int)0;
$sum=(int)array_sum($a);
$i=0;
while($i<$n){
  $sum-=$a[$i];
  $ans+=(int)(($sum%1000000007)*$a[$i])%1000000007;
  $ans%=1000000007;
  ++$i;
}
echo $ans;

Measured memory_bytes: 32116
import bisect
while True:
    len_d = int(input())
    if len_d == 0: break
    n = int(input())
    m = int(input())
    d = [0]
    k = []
    for i in range(1, n):
         d.append(int(input()))
    for i in range(m):
         k.append(int(input()))
    d.sort()
    c = [len_d for i in range(m)]
    ans = 0
    for i in range(m):
        if k[i] == 0: continue
        t = bisect.bisect_left(d, k[i])
        if t == n:
            ans += min(len_d-k[i], k[i]-d[n-1])
        else:
            ans += min(k[i]-d[t-1], d[t]-k[i])
    print(ans)


Measured memory_bytes: 10484
#include<iostream>
#include<cmath>
#define MAX 1000000007
using namespace std;
int a[55][2];
int b[55][2];

int main(){
	int n,m;
	int i,j,k;
	int s[2];
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
	}
	for(i=0;i<m;i++){
		cin>>b[i][0]>>b[i][1];
	}
	for(i=0;i<n;i++){
		s[0]=MAX,s[1]=0;
		for(j=0;j<m;j++){
			k=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]);
			if(k<s[0])s[0]=k,s[1]=j;
		}
		cout<<s[1]+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.ListIterator;

public class Main {
    static final char DOWN = '\\';
    static final char UP = '/';
    static final char FLAT = '_';
    
    private static class Data {
        public int start;
        public int end;
        public int area;
        
        public Data(int start, int end, int area) {
            this.start = start;
            this.end = end;
            this.area = area;
        }
    }

    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception {
        LinkedList<Integer> resolvedList = new LinkedList();
        LinkedList<Integer> slopeStack = new LinkedList();
        LinkedList<Data> unresolvedStack = new LinkedList();

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String landForm = br.readLine();

        for(int pos = 0; pos < landForm.length(); pos++) {
            if(landForm.charAt(pos) == DOWN) {
                slopeStack.add(pos);
                continue;
            } else if(landForm.charAt(pos) == FLAT) {
                continue;
            }
            
            // UP
            if(slopeStack.size() == 0) {
                while(unresolvedStack.size() != 0) {
                    Data data = unresolvedStack.removeFirst();
                    resolvedList.add(data.area);
                }
                continue;
            }

            int before = slopeStack.removeLast();
            Data data = new Data(before, pos, pos - before);
            while(true) {
                if(unresolvedStack.size() == 0) {
                    unresolvedStack.add(data);
                    break;
                }

                Data beforeData = unresolvedStack.removeLast();
                if(beforeData.start > data.start && beforeData.end < data.end) {
                    data.area += beforeData.area;
                } else {
                    unresolvedStack.add(beforeData);
                    unresolvedStack.add(data);
                    break;
                }
            }
        }
        
        int sum = 0;
        int count = 0;
        StringBuilder sb = new StringBuilder();

        ListIterator<Integer> itr = resolvedList.listIterator(0);
        while(itr.hasNext()) {
            int l = itr.next().intValue();
            sum += l;
            count++;

            if(sb.length() != 0) {
                sb.append(" ");
            }

            sb.append(l);
        }

        ListIterator<Data> unItr;
        unItr = unresolvedStack.listIterator(0);
        while(unItr.hasNext()) {
            int l = unItr.next().area;
            sum += l;
            count++;

            if(sb.length() != 0) {
                sb.append(" ");
            }

            sb.append(l);
        }
        System.out.println(sum);
        System.out.print(count);
        if(count == 0) {
            System.out.println();
        } else {
            System.out.println(" " + sb.toString());
        }
    }
}

Measured memory_bytes: 26188
#include <iostream>
#include <algorithm>

using namespace std;

long long b[2000][2000] = {0}, a[2000], ans;

int main(){
  long long N, x;
  ans = 1LL << 62;

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

  for(int k = 0;k < N;k++){
    long long sum = 0;
    for(int i = 0;i < N;i++){
      if(k - 1 >= 0 && i - k >= 0){
        b[i][k] += min(b[i][k-1], a[i-k]);
        sum += b[i][k];
      } else if(i - k < 0){
        b[i][k] += min(b[i][k-1], a[i - k + N]);
        sum += b[i][k];
      } else {
        b[i][k] += min(b[i][N-1], a[i]);
        sum += b[i][k];
      }
    }

    ans = min(ans, k*x + sum);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#include <vector>
#include <limits.h>
#include <stack>
#define maxn 10000000
#define pi acos(-1)
using namespace std;

double aabs(double x)
{
	if(x<0)return -x;
	return x;
}
int gcd(int a,int b)
{
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int main()
{
	stack<int>a;
	int x;
	char s[100];
	while (scanf("%s",s) != EOF)
	{
		if ( s[0] == '+' )
		{
			int q=a.top();
			a.pop();
			int p=a.top();
			a.pop();
			a.push(q+p);
		} 
		else if ( s[0] == '-' )
		{
		int q=a.top();
		a.pop();
		int p=a.top();
		a.pop();
		a.push(p-q);
		} 
		else if ( s[0] == '*' )
		{
		int q=a.top();
		a.pop();
		int p=a.top();
		a.pop();
		a.push(q*p);
		}
		else
		{
			x=0;
			int l=strlen(s)-1;
			for(int i=0;i<strlen(s);i++){x+=(s[i]-'0')*pow(10,l);l--;}
			a.push(x);
		}
	}
	cout<<a.top()<<endl;
	return 0;
}



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

int X, Y;
char mat[101][101];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int x, int y, char c) {
    mat[x][y] = 'X';
    for (int i = 0; i < 4; ++i) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (xx >= 0 && xx < X && yy >= 0 && yy < Y && mat[xx][yy] == c) {
           dfs(xx, yy, c);
        }
    }
}

int main() {
    while (true) {
        cin >> X >> Y;
        if (X == 0 && Y == 0) break;

        for (int i = 0; i < X; ++i) {
            for (int j = 0; j < Y; ++j) {
                cin >> mat[i][j];
            }
        }

        int res = 0;
        for (int i = 0; i < X; ++i) {
            for (int j = 0; j < Y; ++j) {
                if (mat[i][j] != 'X') {
                    dfs(i, j, mat[i][j]);
                    res += 1;
                }
            }
        }

        cout << res << endl;
    }
    return 0;
}



Measured memory_bytes: 3476
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, k := iScan(), iScan()
	ans := k
	for i := 1; i < n; i++ {
		ans *= k - 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
	int i, a;
	char c[31];

	for (i = 1; i <= 30; i++) c[i] = 0;
	for (i = 0; i < 28; i++) cin >> a, c[a] = 1;
	for (i = 1; i <= 30; i++) if (!c[i]) cout << i << endl;

	return 0;
}


Measured memory_bytes: 3104
import sys
#import numpy as np
#import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
n,x=map(int,input().split())
a=list(map(int,input().split()))
res=0
for i in range(n-1):
    s=a[i]+a[i+1]
    if s>x:
        a[i+1]-=(s-x)
        res+=(s-x)
        if a[i+1]<0:
            a[i+1]=0
print(res)

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

using namespace std;
#define int long long 
const int N = 666666;
int arr[N];
int n;
bool cmp(int a,int b){
	return a>b;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>arr[i];
	sort(arr+1,arr+1+n,cmp);
	int sum=arr[1];
	int id=2;
	int f=0;
	for(int i=3;i<=n;i++){
		sum+=arr[id];
		f++;
		if(f==2){
			f=0;id++;
		}
	}
	cout<<sum;
	return 0;
}

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

int main(){
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            int norm = 0;
            for (int k = 0; k < d; k++){
                int diff = abs(x[i][k] - x[j][k]);
                norm += diff * diff;
            }

            bool flag = false;
            for (int k = 0; k <= norm; k++){
                if (k*k == norm){
                    flag = true;
                }
            }
            if (flag){
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input().rstrip('\n')

S += '1' if S[N-1] == '0' else '0'
sumz = [0]*(N+2)
right = 1
cnt = 1
maxlen = 0
left = 0
if K == 0:
    for i in range(N):
        if S[i] == S[i+1] and S[i] == 1:
            cnt += 1
        else:
            if maxlen < cnt:
                maxlen = cnt
            cnt = 1
else:
    cnt = 0
    while True:
        if left >= N: break
        if right <= left: right = left+1
        while (right <N) and ((cnt < K) or ((cnt == K) and ((S[right] == S[right-1]) or S[right] == '1'))):
            if (S[right] != S[right - 1]) and (S[right-1] == '0'):
                cnt += 1
            right += 1

        if not( S[right-1] == '0' and (K == 0)):
            if maxlen < right - left:
                maxlen = right - left
        #next
        while left < N and S[left] == S[left+1]:
            left += 1
        if S[left] == '0':
            cnt -= 1

        left += 1

print(maxlen)

Measured memory_bytes: 10004
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))

    A.sort()
    F.sort(reverse=True)
    r = A[-1]*F[0]
    l = -1
    while(r-l > 1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            if x*y > tmp:
                k += x - (tmp // y)
            #k += max(0, x - (tmp // y))
        if K >= k:
            r = tmp
        else:
            l = tmp
    print(r)


main()


Measured memory_bytes: 33940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll n,m,X,Y,x[110],y[110];
  cin>>n>>m>>X>>Y;
  rep(i,n)cin>>x[i];
  rep(i,m)cin>>y[i];

  for(ll i=X+1;i<=Y;i++){
    ll tmp1=0,tmp2=0;
    rep(j,n){
      if(x[j]>=i){
        tmp1++;
      }
    }
    rep(k,m){
      if(y[k]<i){
        tmp2++;
      }
    }
    if(tmp1==0&&tmp2==0){
      cout<<"No War"<<endl;
      return 0;
    }
  }

  cout<<"War"<<endl;
  return 0;
}


Measured memory_bytes: 3600
import math
A,B=map(int,input().split())
ans=100000
for i in range(1,10001):
    if math.floor(i*0.08)==A and math.floor(i*0.1)==B:
        if i<ans:
            ans=i
if ans==100000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3060
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]

T.sort()

bus=-10**9
cnt=0
ans=0
for t in T:
    if t>bus or cnt>=C:
        bus=t+K
        cnt=1
        ans+=1
    else:
        cnt+=1

print(ans)

Measured memory_bytes: 7532
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	vector<int> sum1(n+1,0),sum2(m+1,0);
	rep(i,n){
		if(s[i]=='A') sum1[i+1]=sum1[i]+1;
		if(s[i]=='B') sum1[i+1]=sum1[i]+2;
	}
	rep(i,m){
		if(t[i]=='A') sum2[i+1]=sum2[i]+1;
		if(t[i]=='B') sum2[i+1]=sum2[i]+2;
	}
	int q;
	cin>>q;
	while(q--){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--,c--;
		if((sum1[b]-sum1[a])%3==(sum2[d]-sum2[c])%3){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    long long int n, i,j,k,sum=0;
    string s;
    getline(cin,s);
    for(i=0;i<s.size();i++)
    {
        if(i%2==0 )
        {
            if(s[i]=='R' || s[i]=='U' || s[i]=='D')
                sum++;
        }
        else
        {
            if(s[i]=='L' || s[i]=='U' || s[i]=='D')
                sum++;
        }
    }
    if(s.size()==sum)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

int main(){
    int n; cin>>n;
    int dpa[100001],dpb[100001],dpc[100001];
    dpa[0]=dpb[0]=dpc[0]=0;
    for(int i=1;i<=n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        dpa[i]=a+max(dpb[i-1],dpc[i-1]);
        dpb[i]=b+max(dpc[i-1],dpa[i-1]);
        dpc[i]=c+max(dpa[i-1],dpb[i-1]);
    }
    cout<<max({dpa[n],dpb[n],dpc[n]})<<endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, p;
  cin >> n >> p;
  ll k = 0, g = 0;
  for(int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if(tmp % 2 == 0){
      g++;
    }else{
      k++;
    }
  }
  
  ll ans = pow(2, g);
  if(k > 0){
    ans *= pow(2, k - 1);
  }else if(p == 1){
    ans = 0;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256