akhauriyash/Code-Regression huggingface dataset:
//package com.atcoder.contest171.c;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        BigInteger bi = new BigInteger(fs.next());
        BigInteger twentySix = new BigInteger("26");
        StringBuilder sb = new StringBuilder();
        while(bi.compareTo(BigInteger.ZERO)  != 0 ){
            BigInteger k = bi.divide(twentySix);
            int last = Integer.parseInt(bi.mod(twentySix).toString());
            if(last == 0){
                k = k.subtract(BigInteger.ONE);
                sb.insert(0,'z');
            }
            else{
                sb.insert(0, (char)('a' + (last-1)));
            }
            bi = k;
        }
        System.out.println(sb.toString());

    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 33232
import java.util.Scanner;
public class Main {
	static final int BALL_NUM = 10;
	int[] ball;
	void run(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0;i < n;i++){
			//????????????????????????
			ball = new int[BALL_NUM];
			for(int j = 0;j < BALL_NUM;j++)
				ball[j] = scan.nextInt();
			if(solve()){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
	boolean solve(){
		int b = 0,c = 0;
		for(int i = 0;i < BALL_NUM;i++){
			if(b >= c){
				if(b < ball[i]){
					b = ball[i];
				}else{
					if(c < ball[i]){
						c = ball[i];
					}else{
						return false;
					}
				}
			}else{
				if(c < ball[i]){
					c = ball[i];
				}else{
					if(b < ball[i]){
						b = ball[i];
					}else{
						return false;
					}
				}
			}
		}
		return true;
	}

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

Measured memory_bytes: 26280
#include <iostream>
using namespace std;
int main(){
	long long int a,b,k;
	cin>>a>>b>>k;
	if(a+b<=k){
	    cout<<'0'<<' '<<'0';
	    return 0;
	}
	else if(a>=k){
		a=a-k;
		cout<<a<<' '<<b;
		return 0;
	}
	else{
		b=a+b-k;
		cout<<'0'<<' '<<b;
		return 0;
    }
	return 0;
}

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

using namespace std;
using ll = long long int;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> x(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll total = 0;
    for(int i = 0;i < n; i++)
    {
        if(i % 2 == 0)
        {
            total += 2 * a[i];
        }else{
            total -= 2 * a[i];
        }
    }
    x[0] = total / 2;
    for(int i = 1; i < n; i++)
    {
        x[i] = 2 * a[i - 1] - x[i - 1];
    }
    for(auto e : x) cout << e << " ";
    cout << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
const int MOD = 1000000007;

int main() {
  int N, L;
  cin >> N >> L;
  vector<int> A;
  rep(i, 0, N) {
    A.push_back(L + i);
  }
  int mn = 1e9;
  rep(i, 0, N) {
    if(abs(mn) > abs(A[i])) mn = A[i];
  }
  int ans = accumulate(A.begin(), A.end(), 0);
  ans -= mn;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> x(n);
	for(auto&& in : x){
		cin >> in;
	}
	vector<int> y = x;

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

	for(int i = 0; i < n; i++){
		if(x[i] < y[n / 2]){
			cout << y[n / 2] << endl;
		} else{
			cout << y[n / 2 - 1] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3712
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
data=[]
for i in range(n+1):
  data.append(abs(a[i]-a[i+1]))
s=sum(data)
for i in range(n):
  print(s-data[i]-data[i+1]+abs(a[i]-a[i+2]))

Measured memory_bytes: 20632
#include<bits/stdc++.h>
using namespace std;
#define free AFEWfeasdifkhsidf
string s;
bool free[138];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>s;
	int pos=s.size();
	int n=pos;
	pos--;
	memset(free,true,sizeof(free));
	for(int i=0;i<s.size();i++)
		free[s[i]]=false;
	if(n!=26){
		for(int i='a';i<='z';i++)
			if(free[i]){
				cout<<s<<(char)(i)<<endl;
				return 0;
			}
	}
	while(pos>=0){
		pos--;
		free[s[pos+1]]=true;
		for(int i=s[pos+1]+1;i<='z';i++)
		{
			if(free[i]){
				cout<<s.substr(0,pos+1)<<(char)i<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define TRUE 0
#define FALSE 1

int main(){
	int i,j,flag[3];
	double x[3],y[3],xp,yp,a[3],b[3],c[3];

	// cy=ax+b
	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&xp,&yp)!=EOF){
		for(i=0;i<3;i++){
			if(i==2){
				if(x[0]-x[i]==0){
					a[i]=1;
					b[i]=-x[i];
					if(x[i]==0) b[i]=0;
					c[i]=0;
				}
				else if(y[0]-y[i]==0){
					a[i]=0;
					b[i]=-y[i];
					if(y[i]==0) b[i]=0;
					c[i]=1;
				}
				else{
					a[i]=(y[0]-y[i])/(x[0]-x[i]);
					b[i]=y[i]-a[i]*x[i];
					c[i]=1;
				}
				
			}
			else{
				if(x[i+1]-x[i]==0){
					a[i]=1;
					b[i]=-x[i];
					if(x[i]==0) b[i]=0;
					c[i]=0;
				}
				else if(y[i+1]-y[i]==0){
					a[i]=0;
					b[i]=-1*y[i];
					if(y[i]==0) b[i]=0;
					c[i]=1;
				}
				else{
					a[i]=(y[i+1]-y[i])/(x[i+1]-x[i]);
					b[i]=y[i]-a[i]*x[i];
					c[i]=1;
				}
			}

			switch(i){
				case 0:
					j=2;
					break;
				case 1:
					j=0;
					break;
				case 2:
					j=1;
			}
			flag[i]=FALSE;
			if((a[i]*x[j]+b[i]-c[i]*y[j])*(a[i]*xp+b[i]-c[i]*yp)>0) flag[i]=TRUE;
		}

		if(flag[0]==TRUE && flag[1]==TRUE && flag[2]==TRUE) printf("YES\n");
		else printf("NO\n");
	}



	return 0;

}

Measured memory_bytes: 612
import sys
input = sys.stdin.readline
T = int(input())

def FloorSum(n, m, a, b):
  # (a * 0 + b) // m + ... + (a * (n - 1) + b) // m
  res = 0
  if a >= m:
    res += (a // m) * n * (n - 1) // 2
    a %= m
  if b >= m:
    res += n * (b // m)
    b %= m
  if a * n + b < m: return res
  u = (a * n + b) // m
  v = (u * m - b)
  res += (n - (v + a - 1) // a) * u + FloorSum(u, a, m, (a - v) % a)
  return res

for _ in range(T):
  n, m, a, b = map(int, input().split())
  print(FloorSum(n, m, a, b))

Measured memory_bytes: 78000
x, y = map(int, input().split())

ans = 0
if x == 3:
    ans += 100000
elif x == 2:
    ans += 200000
elif x == 1:
    ans += 300000


if y == 3:
    ans += 100000
elif y == 2:
    ans += 200000
elif y == 1:
    ans += 300000


if x == 1 and y == 1:
    ans+= 400000

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    string A,s,C;
  	cin >> A >> s >> C;
    cout << A[0] << s[0] << C[0] << endl;
}


Measured memory_bytes: 256
# union find, bfs

import sys
from collections import deque
si = sys.stdin.readline


def main():
    [n, m] = [int(e) for e in si().split()]
    if not m:
        print(1)
        return

    visited = [False]*(n+1)
    fm = [set() for _ in range(n+1)]
    mx = 0

    while m:
        m -= 1
        [a, b] = [int(e) for e in si().split()]
        fm[a].add(b)
        fm[b].add(a)

    for i in range(1, n+1):
        if visited[i]:
            continue
        visited[i] = True
        q = deque()
        q.append(i)
        cnt = 1
        while q:
            curr = q.popleft()
            for e in fm[curr]:
                if not visited[e]:
                    visited[e] = True
                    q.append(e)
                    cnt += 1
        mx = max(mx, cnt)
    print(mx)

if __name__ == '__main__':
    main()


Measured memory_bytes: 72796
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
	int c;
	int t;
}a[1010],b[1010];
int cmp(const node &a,const node &b){
	return a.c<b.c;
}
int main(){
	int n,T;
	cin>>n>>T;
	for(int i=0;i<n;i++){
		cin>>a[i].c>>a[i].t;
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(a[i].t<=T){
			b[cnt]=a[i];
			cnt++;
		}	
	}
	if(cnt==0) cout<<"TLE"<<endl;
	else{
		sort(b,b+cnt,cmp);
		cout<<b[0].c<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long long A,B,C,K;
    cin >> A >> B >> C >> K;
    long long po = 0;
    if (K <= A)
    {
        po = K;
    }
    else if (K <= A + B )
    {
        po = A;
    }
    else{
        po = A - (K -A -B);
    }
    cout << po;
}

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

int main(void) {
	int N;
	string S;
	int x, ans;

	cin >> N >> S;

	x = ans = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'I')
			++x;
		else
			--x;

		if (x > ans)
			ans = x;
	}
	
	cout << ans << '\n';
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool l = false;
  bool r = false;
  if((S[0] == '0' && S[1] != '0') ||
     (S[0] == '1' && (S[1] == '0' || S[1] == '1' || S[1] == '2'))) {
    l = true;
  }
  if((S[2] == '0' && S[3] != '0') ||
     (S[2] == '1' && (S[3] == '0' || S[3] == '1' || S[3] == '2'))) {
    r = true;
  }
  if(l && r)
    cout << "AMBIGUOUS" << endl;
  else if(l)
    cout << "MMYY" << endl;
  else if(r)
    cout << "YYMM" << endl;
  else
    cout << "NA" << endl;
  return 0;
}

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

//082_C

int N,ans,a;

int main(){
    cin>>N;
    int d[N+1]={};
    for(int i=0;i<N;i++){
        cin>>a;
        if(a>N){
            ans++;
        }else {
            d[a]++;
        }
    }
    int sum=0;
    for(int i=0;i<N+1;i++){
        if(d[i]<i){
            ans+=d[i];
        }else {
            ans+=d[i]-i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector<vector<int>> v(3,vector<int>(3));
	for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> v.at(i).at(j);
    }
}
	int n;
	cin >>n;
	vector<int> b(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> b.at(i);
	}
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			for (int k = 0; k < n; ++k)
			{
				if(v.at(i).at(j) == b.at(k)){
					v.at(i).at(j)=0;
				}

			}
		}
	}
	int count=0;
	if(v.at(0).at(0)==0&&v.at(0).at(1)==0&&v.at(0).at(2)==0){
		count++;
	}
	else if(v.at(1).at(0)==0&&v.at(1).at(1)==0&&v.at(1).at(2)==0){
		count++;
	}
	else if(v.at(2).at(0)==0&&v.at(2).at(1)==0&&v.at(2).at(2)==0){
		count++;
	}
	else if(v.at(0).at(0)==0&&v.at(1).at(0)==0&&v.at(2).at(0)==0){
		count++;
	}
	else if(v.at(0).at(1)==0&&v.at(1).at(1)==0&&v.at(2).at(1)==0){
		count++;
	}
	else if(v.at(0).at(2)==0&&v.at(1).at(2)==0&&v.at(2).at(2)==0){
		count++;
	}
	else if(v.at(0).at(0)==0&&v.at(1).at(1)==0&&v.at(2).at(2)==0){
		count++;
	}
	else if(v.at(2).at(0)==0&&v.at(1).at(1)==0&&v.at(0).at(2)==0){
		count++;
	}

  
	if(count==0){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}



	



	


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    if ((a*b)%2==1) {
      System.out.println("Odd");
    } else {
      System.out.println("Even");
    }
  }
}

Measured memory_bytes: 23124
n,k=gets.split.map &:to_i
r,s,p=gets.split.map &:to_i
t=gets.chomp.chars

res=0
rec=[]
t.each_with_index do |e,i|
  case e
  when "r"
    if rec.size < k
      rec << "p"
      res += p
    elsif rec.size >= k
      if rec[i-k] != "p"
        rec << "p"
        res += p
      else
        rec << "."
        res += 0
      end
    end
  when "s"
    if rec.size < k
      rec << "r"
      res += r
    elsif rec.size >= k
      if rec[i-k] != "r"
        rec << "r"
        res += r
      else
        rec << "."
        res += 0
      end
    end
  when "p"
    if rec.size < k
      rec << "s"
      res += s
    elsif rec.size >= k
      if rec[i-k] != "s"
        rec << "s"
        res += s
      else
        rec << "."
        res += 0
      end
    end
  end
end
puts res

Measured memory_bytes: 13948
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	v := nextInt()
	a := n * v
	b := 2 * (n + v)
	fmt.Println(a, b)
}

var sc = bufio.NewScanner(os.Stdin)

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



Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=min(a,k);
	k-=a;
	k-=b;
	if(k>0){
		ans-=k;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll N;
int h[1000];

/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  cin >> N;
  rep(i, N){
    cin >> h[i];
  }

  ll ans = h[0];
  rep(i, N-1){
    ans += max(0, h[i+1]- h[i]);
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
l,r=map(int,input().split())
for i in range(l,r+1):
  if i%2019==0:
    print(0)
    break
else:
  mini=2018
  for i in range(l,r):
    for j in range(i+1,r+1):
      if (i*j)%2019<=mini:
        mini=(i*j)%2019
  print(mini)

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

int main(){
    int wa = 0;
    int i = 0;
    char num[1001];

    while(1){
        cin >> num ;
        if(num[0] == '0'){
            break;
        }
        while(num[i] != '\0'){
            wa += num[i] - '0';
            i++;
        }
        cout << wa << endl;
        wa = 0;
        i = 0;
    }
    return 0;
}




Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
 
int main() {
  int n;
  cin >> n;
  ll dp[n-2][4][4][4];
  rep(i,n-2)rep(j,4)rep(k,4)rep(l,4) dp[i][j][k][l] = 0;
  
  rep(i,4)rep(j,4)rep(k,4){
    if(i==0 && j==2 && k==1) dp[0][i][j][k] = 0;
    else if(i==2 &&j==0 && k==1) dp[0][i][j][k] = 0;
    else if(i==0 && j==1 &&k==2) dp[0][i][j][k] = 0;
    else dp[0][i][j][k] = 1;
  }  

  for(int len=1;len<n-2;len++){
    rep(next,4)rep(i,4)rep(j,4)rep(k,4){
      if(j==0 && k==2 && next==1) ;
      else if(j==2 && k==0 && next==1) ;
      else if(j==0 && k==1 && next==2) ;
      else if(i==0 && j==2 && next==1) ;
      else if(i==0 && k==2 && next==1) ;
      else dp[len][j][k][next] = (dp[len][j][k][next] + dp[len-1][i][j][k])%MOD ;      
    }
  }
  
  ll ans = 0;
  rep(i,4)rep(j,4)rep(k,4){
    ans = (ans + dp[n-3][i][j][k])%MOD;
  }
  
  /*rep(len,n-2){
    rep(i,4)rep(j,4)rep(k,4){
      cout << dp[len][i][j][k] <<  " " ;
    }
    cout << endl;
  }*/
        
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(N), B(N);
  REP(i, N) cin >> A[i];
  

  int sum = 0;
  REP(i, N) sum += A[i];

  int k = sum/(N*(N+1)/2);
  if(sum%(N*(N+1)/2) != 0){
    NO; return 0;
  }
  REP(i, N) B[i] = A[(i+1)%N]-A[i]-k;

  int ans = 0;
  REP(i, N){
    while(B[i] < 0){
      B[i] += N;
      ans++;
    }
  }

  REP(i, N){
    if(B[i] != 0){
      NO;
      return 0;
    }
  }

  ans == k? YES: NO;

  return 0;
}

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

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    int match = n;
    for (int i = 0; i < n; i++) {
        string ss = s.substr(i);
        string tt = t.substr(0, n-i);

        if (ss == tt) break;
        match--;
    }
    cout << n*2-match << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
using namespace std;
int ab(int k, vector<int> x,int n) {
	return (x.at(n) < (k > x.at(n) ? k - x.at(n) : x.at(n) - k)) ? x.at(n) : (k > x.at(n) ? k - x.at(n) : x.at(n) - k);
}
int main() {
	int n, k;
	cin >> n >> k;
	vector<int>x(n);
	for (int i = 0; i < n; i++) {
		cin >> x.at(i);
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += ab(k, x, i)*2;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3596
s = bytearray(raw_input())
N = int(raw_input())
dis = [ord('z')-c for c in s]

for idx, d in enumerate(dis[:-1]):
    if d!=25 and d+1 <= N:
        s[idx] = 'a'
        N -= (d+1)

if N > 0:
    N %= 26
    t = (dis[-1]-N) % 26
    s[-1] = chr(ord('z') - t)
print s

Measured memory_bytes: 4484
#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
ll inf=1000000000000000000,mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        ll t;cin>>t;ll a,b;cin>>a>>b;
        for(ll i=a;i<=b;i++){
            if(i%t==0){
                cout<<"OK";
                return 0;
            }
        }
        cout<<"NG";

}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	auto no=[&](){cout<<"0\n",exit(0);};
	int n;
	cin>>n;
	vector<int>d(n);
	for(int i=0;i<n;i++) cin>>d[i];
	int maxn=*max_element(d.begin(),d.end());
	if(maxn>n-1) no();
	vector<int>cnt(maxn+1);
	for(int i=0;i<n;i++) cnt[d[i]]++;
	if(cnt[0]!=1)no();
	if(d[0]!=0)no();
	int64_t ans=1;

	for(int i=1;i<cnt.size();i++){
		if(cnt[i]==0)no();
		for(int j=0;j<cnt[i];j++)
			ans= ans * cnt[i-1] % 998244353;
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 1024
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

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

const int N=100000+10;
const int mod=1e9+7;
int qpow(int a,int b) { int c=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
	return c;
}

int n,a[N];

int main() {
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+n+1);
	if (n&1) {
		int flag=(a[1]==0);
		for (int i=2;i<=n;i+=2)
			if (a[i]!=i||a[i+1]!=i) { flag=0; break; }
		if (flag) printf("%d\n",qpow(2,n/2));
		else puts("0");
	} else {
		int flag=1;
		for (int i=1;i<=n;i+=2)
			if (a[i]!=i||a[i+1]!=i) { flag=0; break; }
		if (flag) printf("%d\n",qpow(2,n/2));
		else puts("0");
	}
	return 0;
}


Measured memory_bytes: 4148
N = int(input())
A = list(map(int,input().split()))
ma = max(A)
l = [0 for _ in range(ma + 10)]
for i in range(N):
    temp = A[i]
    while(temp <= ma + 5):
        l[temp] += 1
        temp += A[i]
ans = 0
for i in range(N):
    if l[A[i]] == 1:  ans += 1
print(ans)

Measured memory_bytes: 171208
import java.util.Scanner;
public class Main {

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

            String line = sc.next();

            int t;
            int sum = 0;

            for (int i = 0; i < line.length(); i++) {

                t = line.charAt(i) - '0';
                sum += t;

                if (sum == 0) {
                    break outer;
                }
            }
            System.out.println(sum);
        }
    }
}



Measured memory_bytes: 26380
#include <stdio.h>
int main()
{
  int i, m, f, r;
  while(1){
    scanf("%d %d %d",&m, &f, &r); 
    if(m == -1 && f == -1 && r == -1)break;
    if(m == -1 || f == -1){
      printf("F\n");
    }else if((m + f) >= 80){
      printf("A\n");
    } else if((m + f) >= 65 && (m + f) < 80){
      printf("B\n");    
    } else if((m + f) >= 50 && (m + f) < 65){
      printf("C\n");
    } else if((m + f) >= 30 && (m + f) < 50){
      if(r >= 50){
	printf("C\n");
      }else printf("D\n");
    } else if((m + f) < 30){
      printf("F\n");
    }
  }
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    uint A, B, count{0};
    cin >> A >> B;
    for (auto &&i: irange(A, B+1)){
        string s{to_string(i)};
        bool flag{true};
        for (auto &&j: irange(0U, (uint)s.size())){
            if(s.at(j)!=s.at(s.size()-j-1))flag=false;
        }
        if(flag)count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
  
u_int getDigit(u_int n){
    u_int digit = 0;
      
    while(n > 0){
        n /= 10;
        ++digit;
    }
      
    return digit;
}
    
int main(){
    u_int a, b;
      
    while(std::cin >> a >> b){
        std::cout << getDigit(a + b) << std::endl;
    }
      
    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	vector<int> a(n+1, 0), b(n, 0);
	for (int i = 0; i < n+1; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

	long long defeat = 0;
	for (int i = 0; i < n; i++) {
		int tmp = min(a[i], b[i]);
		defeat += tmp;
		a[i] -= tmp;
		b[i] -= tmp;

		int tmp2 = min(a[i+1], b[i]);
		defeat += tmp2;
		a[i+1] -= tmp2;
		b[i] -= tmp2;
	}

	cout << defeat << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char b;
    cin >> b;
    if(b == 'A') cout << 'T';
    else if(b == 'C') cout << 'G';
    else if(b == 'G') cout << 'C';
    else cout << 'A';
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
x = list(map(int,input().split()))
s = 0
for i in range(n-1):
  if (x[i+1]-x[i])*a > b:
    s += b
  else:
    s += (x[i+1]-x[i])*a 
print(s)
    
         
                    

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

ll getDigit(ll n) {
    return to_string(n).size();
}

int main() {
    ll n;
    cin >> n;
    ll ans = 1001001001;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ans = min(ans, max(getDigit(i), getDigit(n / i)));
        }
    }
    cout << ans << endl;
}


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

long long n;

void func (long long cur, int use, long long &counter) {
    if (cur > n) return;
    if (use == 0b111) ++counter;

    func(cur * 10 + 7, use | 0b001, counter);
    func(cur * 10 + 5, use | 0b010, counter);
    func(cur * 10 + 3, use | 0b100, counter);
}

int main() {
    cin >> n;
    long long ans = 0;
    func(0, 0, ans);
    cout << ans << endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector < int > v(n);
	for (int i = 0; i < n; i++)
		cin>>v[i];
	int res = 0;
	for (int i = n - 1; i >= 0;) {
		int j = i;
		while ((j - 1 >= 0) && v[j - 1] >= v[j])
			j--;
		res = max(res, i - j);
		i = j - 1;
	}
	cout<<res;
}


Measured memory_bytes: 640
import sys
a,b = map(int, input().split())
c = 0
if a*4<b:
    print('No')
    sys.exit()
while a!=0:
    if a*2+c*4==b or a*4+c*2==b:
        print('Yes')
        sys.exit()
    a-=1
    c+=1
print('No')

Measured memory_bytes: 9144
N = int(input())
A, B = [], []
for i in range(N):
  a, b = map(int, input().split())
  A += [a]
  B += [b]

A.sort()
B.sort()
if N%2 == 1:
  med_minimum = A[(N-1)//2]
  med_maximum = B[(N-1)//2]
else:
  med_minimum = (A[(N-2)//2] + A[(N-2)//2+1])
  med_maximum = (B[(N-2)//2] + B[(N-2)//2+1])
print(med_maximum - med_minimum + 1)


Measured memory_bytes: 25408
#include <stdio.h>
int main(void)
{
    int a,b,c,d,i=0,j,n,trues[100]={0};
    while(scanf("%d",&n)!=EOF)
    {
        for(a=0;a<10;a++)
            for(b=0;b<10;b++)
                for(c=0;c<10;c++)
                    for(d=0;d<10;d++)
                        if(n==a+b+c+d)
                            trues[i]++;
        i++;
    }
    for(j=0;j<i;j++)
        printf("%d\n",trues[j]);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n,k,x,y;
	cin>>n;
	cin>>k;
	cin>>x;
	cin>>y;
	if(n>k){
		cout<<k*x+(n-k)*y<<endl;
	}
	else cout<<n*x<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int k = n - 1;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (k <= 0) break;
        if (k > 0) {
            k--;
            ans += a[i];
        }
        if (i == n - 1) continue;
        if (k > 0) {
            k--;
            ans += a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x',
                 'y','z'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v;

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  
  ll tmp;
  for (int i=0;i<n;i++){
    //cin >> tmp;
    cin >> vec[i];
    //vec.push_back(tmp);
  }
  
  //sort(vec.begin(), vec.end(), greater<ll>());
  sort(vec.begin(), vec.end());
  //for (int i=0;i<n;i++) cout << vec[i] << endl;
  //vec = {4,3,2,1};
  
  ll ans = 0;
  //auto iter;
  ll idx;
  for (int i=n-1;i>=0;i--){
    for (int j=i-1;j>=0;j--){
      auto iter = upper_bound(vec.begin(), vec.end(), vec[i] - vec[j]);
      //auto iter = lower_bound(vec.begin(), vec.end(), key);
      //cout << *iter << endl;
      //if (iter == vec.()) continue;
      idx = distance(vec.begin(), iter);
      if (idx < 0) continue;
      //cout << i << " " << j << " " << idx << endl;
      //cout << vec[i] << " " << vec[j] << " " << vec[idx] << endl;
      if (j - idx > 0) ans += (j - idx);
      //cout << vec[i] << " " << vec[j] << " " << vec[idx] << endl;
    }
  }

  cout << ans << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int f, s;

  f = (a == 5) + (b == 5) + (c == 5);
  s = (a == 7) + (b == 7) + (c == 7);

  if(f == 2 && s == 1) {
    cout << "YES";
  }
  else
    cout << "NO";
  cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <deque>

using namespace std;

int n=0;//num
int r=0;//round

//just simulate
int main(int args, char *argc[]){
  while(cin>>n>>r){
    if(n==0 && r==0)
      return 0;
    deque<int> cards;
    for(int i=0;i<n;i++)
      cards.push_front(i+1);

    //test
    /*for(int i=0;i<n;i++)
      printf("[%d]:%d ",i,cards[i]);
      puts("");
     */

    int a,b;
    for(int i=0;i<r;i++){
      cin>>a>>b;
      //for(int ix=a-1;ix<=a+b-2;ix++){
      for(int ix=a+b-2;ix>=a-1;ix--){
        int temp=cards[a+b-2];
/*        printf("i:%d ix:%d temp:%d\n",i,ix,temp);*/
        cards.erase(cards.begin()+(a+b-2));
        cards.push_front(temp);
      }
/*      printf("i--%d a:%d b:%d -- ",i,a,b);
      for(int i=0;i<n;i++)
        printf("[%d]:%d ",i,cards[i]);
      puts("");*/
    }

/*    cout<<"last\n";
    for(int i=0;i<n;i++)
      printf("[%d]:%d ",i,cards[i]);
    puts("");*/
    cout<<cards[0]<<endl;

    }
    return 0;
  }


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans;
  int d = max(a, max(b, c));
  if (d == a) ans = a*10 + b + c;
  else if (d == b) ans = b*10 + a + c;
  else if (d == c) ans = c*10 + a + b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

def min(a,b)
  return a>b ? b : a
end
n,m=get_i
c=get_i
dp=array(n+1,1,Float::INFINITY)

dp[0]=0
for i in 1..n
  m.times do|j|
    next if i-c[j]<0
    dp[i]=min(dp[i],dp[i-c[j]]+1)
  end
end
puts dp[n]


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    int tmp;

    
    REP(i, (n/4)+1)
        REP(j,(n/7)+1){
            tmp = i*4+j*7;
            if(tmp==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    Problem 98
    https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int mod = 1000000007;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<int> cnt(N, 0);
    cnt[0] = 3;
    ll ans = 1;
    for (int i = 0; i < N; i++) {
        ans *= cnt[a[i]]--;
        ans %= mod;
        cnt[a[i]+1]++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4496
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vi a(n);
	int x = 0;
	set<int> st;
	rep(i, 0, n) {
		cin >> a[i];
		if (1 <= a[i] && a[i] < 400) {
			st.insert(1);
		}
		else if (400 <= a[i] && a[i] < 800) {
			st.insert(2);
		}
		else if (800 <= a[i] && a[i] < 1200) {
			st.insert(3);
		}
		else if (1200 <= a[i] && a[i] < 1600) {
			st.insert(4);
		}
		else if (1600 <= a[i] && a[i] < 2000) {
			st.insert(5);
		}
		else if (2000 <= a[i] && a[i] < 2400) {
			st.insert(6);
		}
		else if (2400 <= a[i] && a[i] < 2800) {
			st.insert(7);
		}
		else if (2800 <= a[i] && a[i] < 3200) {
			st.insert(8);
		}
		else {
			x++;
		}
	}
	int min = st.size();
	if (min == 0) {
		min++;
	}
	int max = st.size() + x;
	cout << min << " " << max << endl;
	return 0;
}


Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
int N;


int main(){

    string S,T;
    cin >> S;
    cin >> T;

    int cnt=0;
    rep(i,3){
        if(S.substr(i,1)==T.substr(i,1)) cnt++; 
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char a[11];
  int n,cur=0,max=0,i,j;
  scanf("%s",&a);
  n = sizeof(a);
  for(i=0;i<n;i++){
      if((a[i] != 'A')&&(a[i] != 'T')&& (a[i] != 'C')&& (a[i] != 'G')){
        cur = 0;
      }
      else{
        cur++;
        if(cur>max){
          max = cur;
        }
      }
  }
  printf("%d",max);
}


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

int main() {
    int n;
    int a[55][26] = {{0}};
    cin >> n;
    REP(i, n){
        string str;
        cin >> str;
        REP(j, str.size()) a[i][str[j] - 'a']++;
    }

    string ans;
    REP(i, 26){
        int mini = a[0][i];
        REP(j, n) mini = min(a[j][i], mini);
        REP(j, mini) ans += i + 'a';
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
int A,B,C;
cin >> A>>B>>C;
if (A==B &&A!=C &&B!=C)
    cout << C;
else
   if (A==C &&A!=B &&C!=B)
    cout << B;
else
   if (B==C &&A!=B &&C!=A)
    cout << A;

return 0;
}


Measured memory_bytes: 256
N, K=map(int, input().split())
a=list(map(int, input().split()))
A=a*2
base=0
matagu=0
for i in range(N):
  for j in range(i+1,2*N):
    if A[i]>A[j]:
      if j>=N:
        matagu+=1
      else:
        base+=1
baserep=K
matagurep=K*(K-1)//2
waru=10**9+7
ans=(base*baserep+matagu*matagurep)%waru
print(ans)

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

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

Measured memory_bytes: 256
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
struct unionfind{
  int par[100010]; // 親ノード  必要に応じて要素数を変えよう
  int rank[100010]; // ランク　必要に応じて要素数を変えよう
  unionfind(int n){
    init(n);
  }
  void init(int n){
    for(int i=0;i<=n;i++){
      par[i]=i;
      rank[i]=1;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }
  int size(int x){
    return rank[root(x)];
  }
  bool same(int x,int y) {
    return root(x) == root(y);
  }
  void unite(int x,int y) {
    x=root(x);
    y=root(y);
    if(x==y){
      return;
    }
    if(rank[x]<rank[y]){
      swap(x,y);
    }
    rank[x]=rank[x]+rank[y];
    par[y]=x;
  }
};
struct edge{
    int from;
    int to;
    int cost;
    edge(int f,int t, int w) :from(f), to(t), cost(w) { }
};
bool comp(const edge& e1,const edge& es){
  return e1.cost<es.cost;
}
int main(){
  while(1){
    int n;
    scanf("%d\n",&n);
    if(n==0){
      break;
    }
  int i,m,a,b,d,ans=0;
  vector<edge> g;
    unionfind tree(110);
  scanf("\n%d\n",&m);
  for(i=0;i<m;i++){
    scanf("%d,%d,%d\n",&a,&b,&d);
    g.push_back(edge(a,b,d));
  }
  sort(g.begin(),g.end(),comp);
  for(i=0;i<m;i++){
    if(tree.same(g[i].to,g[i].from)==0){
      tree.unite(g[i].to,g[i].from);
      ans+=g[i].cost/100-1;
    }
  }
    printf("%d\n",ans);
  }
  return 0;
}


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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int q1 = 0,q2 = 0,q3 = 0;
  rep(i,0,n){
    int p;
    cin >> p;
    if(p <= a) q1++;
    else if(p <= b) q2++;
    else q3++;
  }
  int m = min(q1,q2);
  m = min(m,q3);
  cout << m << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N) {
    ans++;
    N /= K;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int $=1;
    //cin>>$;
    while($--)
    {
        ll n,x,t;
        cin>>n>>x>>t;
        ll a=(n+x-1)/x;
        a*=t;
        cout<<a<<endl;
    }
}


/*
8888888888888888888888888888
    Md. Masud Mazumder
    University of Chittagong
    Department of CSE
8888888888888888888888888888
*/


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n, k;
    cin >> n >> k;

    n = n - n / 2;
    if(n >= k){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}



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

int merge_sort(int S[], int left, int right) {
    int cnt = 0;
    if (left == right) return cnt;
    int mid = (left + right) / 2;
    cnt += merge_sort(S, left   , mid  );
    cnt += merge_sort(S, mid + 1, right);
    queue<int> A;
    queue<int> B;
    for (int i = left; i <= mid; i++) {
        A.push(S[i]);
    }
    A.push(1e9 + 1);
    for (int i = mid + 1; i <= right; i++) {
        B.push(S[i]);
    }
    B.push(1e9 + 1);

    for (int i = left; i <= right; i++) {
        cnt++;
        if (A.front() <= B.front()) {
            S[i] = A.front();
            A.pop();
        } else {
            S[i] = B.front();
            B.pop();
        }
    }
    return cnt;
}

int main(){
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int cnt = merge_sort(S, 0, n - 1);
    cout << S[0];
    for (int i = 1; i < n; i++) {
        cout << " " << S[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6868
// https://atcoder.jp/contests/abc136/tasks/abc136_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: i32, b: i32, c: i32
    };
    println!("{}", max(0, c-(a-b)));
}


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

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

    vector <int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];

    for (int i = 0; i < n; i++) {
        for (int j = i; j > 0; j--) {
            if (v[j] >= v[j-1]) break;
            swap(v[j], v[j-1]);
        }

        for (int j = 0; j < n; j++) {
            if (j) cout << " ";
            cout << v[j];
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 3084
//https://codeforces.com/contest/955/problem/C
    
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","rb",stdin);
    // #endif

    int n;
    string s; 
    cin >> n >> s;
  
  int hash[26] = {};

  for( int  i = 0 ; i < n ; i++) hash[s[i] - 'a']++;
  int mod = 1e9 + 7;
  int ans = 1;
  for(int i = 0; i < 26 ; i++){
  		if(hash[i]!=0){
  			ans = ((ans%mod)*((hash[i] + 1)%mod))%mod;
  		}
  } 
 	cout << ans - 1;
}

Measured memory_bytes: 512
#include<stdio.h>


#define MAX 101
#define INF 2001
 
int main(){
int i,j,n,u,v,sum=0,mincost,E[MAX][MAX],color[MAX],d[MAX];
 
scanf("%d",&n);
for(i=1 ; i<=n ; i++){
for(j=1 ; j<=n ; j++){
scanf("%d",&E[i][j]);
if(E[i][j]==-1)E[i][j]=INF;
}
}
 


for(u=1 ; u<=n ; u++){
d[u]=INF;
color[u]=0;      //white
}


d[1]=0;
 
while(1){
mincost=INF;
for(i=1 ; i<=n ; i++){
if(color[i] != 1 && d[i] < mincost){
mincost=d[i];    
u=i;
}
}
    
if(mincost==INF)break;
color[u] = 1;     //black

for(v=1 ; v<=n ; v++){
if(color[v] != 1 && E[u][v] < d[v]){
d[v]=E[u][v];
}
}
}
   
for(i=1 ; i<=n ; i++){
sum += d[i];
}
 
printf("%d\n",sum);
 
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i, num, res;
    int a, b, c, d;
    while(cin >> a >> b >> c >> d)
    {
        if((a+b) > (c+d))
        {
            cout << "Left" << endl;
        }
        else if((a+b) == (c+d))
        {
            cout << "Balanced" << endl;
        }
        else
        {
            cout << "Right" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
ll check(string s,string t)
{
    ll i,c=0;
    for(i=0;i<s.length();i++)
     c+=s[i]!=t[i];
    return c; 
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       string s,t;
       cin>>s>>t;
       ll i,ans=INF;
       ll n=s.length(),m=t.length();
       for(i=0;i<=n-m;i++)
       {
           ans=min(ans,check(s.substr(i,m),t));
       }
       cout<<ans;
   }
}

Measured memory_bytes: 3620