akhauriyash/Code-Regression huggingface dataset:
N = int(input())

def query(s):
    q = ['?']
    for c in s:
        q.append(c+1)
    print(*q)
    res = input()
    if res=='-1':
        exit()
    return res[0]

color = query(list(range(N)))
ok = 0
ng = N
while ng-ok > 1:
    m = (ok+ng)//2
    if query(list(range(m,N+m))) == color:
        ok = m
    else:
        ng = m

ans = ['_'] * (2*N)
st = set(range(ok+1,ok+N))
for i in range(N*2):
    if i in st: continue
    st.add(i)
    res = query(st)
    ans[i] = res
    st.remove(i)

st = set()
b = r = 0
for i,c in enumerate(ans):
    if c=='B' and b<N//2:
        b += 1
        st.add(i)
    elif c=='R' and r<N//2:
        r += 1
        st.add(i)
for i in range(N*2):
    if ans[i] != '_': continue
    st.add(i)
    res = query(st)
    ans[i] = res
    st.remove(i)

print('! ' + ''.join(ans))

Measured memory_bytes: 3908
N = int(input())
S = input()

max_count = 0
for i in range(0, N-1):
  X = S[0:i+1]
  Y = S[i+1:]

  X_set = set(X)
  Y_set = set(Y)

  count = len(X_set & Y_set)
  if max_count < count:
    max_count = count

print(max_count)


Measured memory_bytes: 9100
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int n;
    cin >> n;

    vector< vs32 > a(n, vs32(n, 0));
    int u, v;
    int c;
    rep (i, n)
    {
        cin >> u >> c;
        --u;
        rep (i, c)
        {
            cin >> v;
            --v;
            a[u][v] = 1;
        }
    }

    rep (i, n)
    {
        rep (j, n)
        {
            if (j > 0)
            {
                cout << " ";
            }
            cout << a[i][j];
        }
        cout << "\n";
    }

    return 0;
}



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

using namespace std;

const int MOD = 1000000007;
const int MAXN = 1000005;

int mul (int x, int y) {return 1LL * x * y % MOD;}
int add (int x, int y) {x += y; if (x >= MOD) return x - MOD; return x;}
int sub (int x, int y) {x -= y; if (x < 0) return x + MOD; return x;}

int a, b, c, sol;
int fct[MAXN], inv[MAXN];

int pot (int a, int e) {
    int res = 1;
    while (e > 0) {
        if (e & 1) res = mul(res, a);
        a = mul(a, a);
        e /= 2;
    }
    return res;
}

void precompute () {
    fct[0] = inv[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        fct[i] = mul(fct[i - 1], i);
        inv[i] = pot(fct[i], MOD - 2);
    }
}

int nck (int n, int k) {
    return mul(fct[n], mul(inv[n - k], inv[k]));
}

void calc () {
    if (b > c) swap(b, c);
    int curr = 0, uk = 1;
    for (int len = 0; len <= b + c; len++) {
        int val = sub(uk, curr);
        val = mul(val, nck(len + a - 1, a - 1));
        val = mul(val, pot(3, b + c - len));
        sol = add(sol, val);
        uk = sub(add(uk, uk), nck(len, min(len, b)));
        if (len < b) uk = add(uk, 1);
        if (len == c) {
            curr = 1;
        } else if (len > c) {
            curr = add(sub(add(curr, curr), nck(len, len - c - 1)), nck(len + 1, len - c));
        }
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    precompute();
    cin >> a >> b >> c;
    calc();
    cout << sol;
    return 0;
}


Measured memory_bytes: 8064
"use strict";
    
const main = arg => {
    const A = arg.split("\n")[0].split(" ")[0];
    const B = arg.split("\n")[0].split(" ")[1];
    let cnt = 0;
    
    for(let i=A; i<=B; i++) {
        if(String(i) == String(i).split("").reverse().join("")) {
            cnt++;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 13480
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

map<int,int> factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////

signed main() {
string s;
cin>>s;
int n;
n=s.size();
int k;
cin>>k;

int dp[100][4][2];
rep(i,100)rep(j,4)rep(k,2)dp[i][j][k]=0;
dp[0][1][1]=s[0]-'0'-1;
dp[0][0][1]=1;
dp[0][1][0]=1;
rep(i,n-1){
  if(s[i+1]!='0'){
    dp[i+1][0][1]=dp[i][0][1];
    for(int j=1;j<4;j++){
      dp[i+1][j][1]=dp[i][j][1]+dp[i][j-1][1]*9+dp[i][j][0]+dp[i][j-1][0]*(s[i+1]-'0'-1);
      dp[i+1][j][0]=dp[i][j-1][0];
  }
}
else {
  dp[i+1][0][1]=dp[i][0][1];
  for(int j=1;j<4;j++){
    dp[i+1][j][1]=dp[i][j][1]+dp[i][j-1][1]*9+dp[i][j-1][0]*(s[i+1]-'0');
    dp[i+1][j][0]=dp[i][j][0];
}
}

}
cout<<dp[n-1][k][0]+dp[n-1][k][1]<<endl;
}


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

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

	int a[3], b[3], c[3][3], a2[3], a3[3];
	for (int i = 0; i < 3; ++i){
		for (int j = 0; j < 3; ++j){
			cin >> c[i][j];
		}
	}
	for (a[0] = 0; a[0] <= 100; a[0]++){
		for (int j = 0; j < 3; ++j){
			b[j] = c[0][j] - a[0];
		}
		for (int j = 0; j < 3; ++j){
			a2[j] = c[1][j] - b[j];
		}
		if (a2[0] != a2[1] || a2[1] != a2[2]){
			continue;
		}
		for (int j = 0; j < 3; ++j){
			a3[j] = c[2][j] - b[j];
		}
		if (a3[0] != a3[1] || a3[1] != a3[2]){
			continue;
		}
		cout << "Yes" << "\n";
		return 0;
	}
	cout << "No" << "\n";
	return 0;
}

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

struct N {
	int l, r, p, d, h;
	int deg, sib;
	int setd(int d);
	void print();
};

int n, root;
N T[25];
int md;

int N::setd(int _d){
	h = 0;
	d=_d++;
	deg=0;
	if (md<d)md=d;
	if (l!=-1)
	{
		h = T[l].setd(_d);
		deg++;
	}
	if(r!=-1)
	{
		int mh = T[r].setd(_d);
		if (mh>h) h = mh;
		deg++;
	}
	if(deg ==2)
	{
		T[r].sib=l;
		T[l].sib=r;
	}
	return h+1;
}

void N::print()
{
	int id =this-T;
	cout<< "node " <<id;
	cout<<": parent = "<<p;
	cout<<", sibling = "<<sib;
	cout<<", degree = "<<deg;
	cout<<", depth = "<<d;
	cout<<", height = "<<h;
	if (id==root) cout<<", root"<<endl;
	else if (deg==0) cout<<", leaf"<<endl;
	else cout<<", internal node"<<endl;
}


int main()
{
	memset(T,-1,sizeof(T));
	cin >>n;
	for(int i=0;i<n;i++){
		int id, l, r;
		cin>>id>>l>>r;
		T[id].l=l;
		T[id].r=r;
		T[l].p=id;
		T[r].p=id;
	}
	for(int i=0;i<n;i++){
		if(T[i].p==-1) {
			root=i;
			break;
		}
	}
	T[root].setd(0);
	for(int i=0;i<n;i++){
		T[i].print();
	}
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        // 主処理
        boolean judge = (Math.abs(c - a) <= d) || (Math.abs(b - a) <= d && Math.abs(c - b) <= d);
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	int h, a;
	cin >> h >> a;
	int ans = h/a;
	if(h%a)
		ans++;
		
	cout << ans;
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> cleart;
		while(t--){
			solve();
		}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int sum = (H2-H1)*60+(M2-M1);
	sum -= K;
	cout << sum << endl;
}

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

int main() {
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;

}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

const int mod = 1000000007;
struct mint {
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
int main() {
    lint n, a, b;
    cin >> n >> a >> b;
    mint mn(n), ma(a), mb(b);

    mint ans = mint(2).pow(n) - mint(1);
    mint aa(1), bb(1);
    rep(i, a) { aa *= (mn - mint(i)) / mint(i + 1); }
    rep(i, b) { bb *= (mn - mint(i)) / mint(i + 1); }
    ans -= aa;
    ans -= bb;
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j,k,c[9][9],a[9];
string b[9];
cin>>n;
for(k=0;k<n;k++){
if(k>0)cout<<endl;
for(i=0;i<9;i++)
for(j=0;j<9;j++)cin>>c[i][j];
for(i=0;i<9;i++)b[i]="         ";
for(i=0;i<9;i++){
for(j=0;j<9;j++)a[j]=0;
for(j=0;j<9;j++)a[c[i][j]-1]++;
for(j=0;j<9;j++)if(a[c[i][j]-1]>1)b[i][j]='*';
}
for(i=0;i<9;i++){
for(j=0;j<9;j++)a[j]=0;
for(j=0;j<9;j++)a[c[j][i]-1]++;
for(j=0;j<9;j++)if(a[c[j][i]-1]>1)b[j][i]='*';
}
for(i=0;i<9;i++){
for(j=0;j<9;j++)a[j]=0;
for(j=0;j<9;j++)a[c[i/3*3+j/3][(i*3)%9+j%3]-1]++;
for(j=0;j<9;j++)if(a[c[i/3*3+j/3][(i*3)%9+j%3]-1]>1)b[i/3*3+j/3][(i*3)%9+j%3]='*';
}
for(i=0;i<9;i++){
for(j=0;j<9;j++)cout<<b[i][j]<<c[i][j];
cout<<endl;
}
}
return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cmath>
 
using namespace std;
 
int main(){
	int a, b, c, n;
	
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> a >> b >> c;
	if(a<b) swap(a,b);
	if(a<c) swap(a,c);
	if(a*a == b*b + c*c) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}

	return 0;

}



Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

 
int main() {
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n);i++)
int main(){
  string s,t; cin >> s >>t;
  int count = 0;
  rep(i,3) {
    if(s.at(i) == t.at(i)) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a_dict = {}
sum = 0
for i in range(n):
    if a[i] not in a_dict:
        a_dict[a[i]] = 0
    a_dict[a[i]] += 1
    sum += a[i]
q = int(input())
for i in range(q):
    b,c = map(int, input().split())
    # bがcになったときに増加する数を数えれば良い
    # b*bの数を引いて c*cの数を足せば良い
    if b in a_dict:
        tmp = a_dict[b]
        a_dict[b] = 0
        if c not in a_dict:
            a_dict[c] = 0
        a_dict[c] += tmp
        sum = sum + tmp * c - tmp * b

    #ans = 0
    #for key,value in a_dict.items():
    #    ans += key*value
    print(sum)



Measured memory_bytes: 85424
import java.lang.Math.floor
import java.lang.Math.sqrt

/**
 * @author karayuu
 */
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  var count = 0
  (1..n).forEach {
    if (素数かどうか判定(readLine()!!.toInt())) {
      count++
    }
  }

  println(count)
}

fun 素数かどうか判定(x: Int): Boolean {
  if (x == 2) return true
  if (x < 2 || x % 2 == 0) return false
  for (i in 3..floor(sqrt(x.toDouble())).toInt()) {
    if (x % i == 0) {
      return false
    }
  }
  return true
}


Measured memory_bytes: 32388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    ll n;
    int k;
    cin >> n >> k;
    int ans;
    while(n){
        n/=k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
typedef long long ll;

int L, A, B, C, D;

int main(void) {
    cin >> L;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    int day;
    if (A % C != 0) day += A/C+1;
    else day += A/C;
    if (B % D != 0) day = max(day, B/D+1);
    else day = max(day, B/D);
    cout << L - day << endl;

    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back

main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int a,b;
	cin>>a>>b;

	if(a<=5)
		cout<<0;
	else if(a<=12)
		cout<<b/2;
	else 
		cout<<b;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] h = new int[n];
    for(int i=0;i<n;i++){
      h[i] = sc.nextInt();
    }
    for(int j=1;j<n;j++){
      int check = 1;
      for(int k=0;k<j;k++){
        if(h[j] < h[k]){
          check = 0;
        }
      }
      if(check == 1){
        count++;
      }
    }
    System.out.println(count+1);
  }
}

Measured memory_bytes: 23636
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
flg = False
for i in range(n):
    if not flg:
        if s[i] == 'h':
            flg = True
            continue
    else:
        if s[i] == 'i':
            flg = False
            continue
    print('No')
    quit()
if s[-1] != 'i':
    print('No')
else:
    print('Yes')

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

int dfs(vvi &G,int v = 0,int p = -1) {
    vi d;
    for(int u : G[v]) {
        if(u == p) continue;
        d.pb(dfs(G,u,v));
    }
    if(d.size() == 0) return 1;
    sort(rall(d));
    rep(i,d.size()) d[i] += i;
    return *max_element(all(d))+1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vvi G(n);
    rep(i,n-1) {
        int a;
        cin >> a;
        a--;
        G[a].pb(i+1);
        G[i+1].pb(a);
    }
    cout << dfs(G)-1 << endl;
}


Measured memory_bytes: 19496
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define all(x) x.begin(),x.end()
using namespace std;
int n,a[100];
vector<int> v;
int main(){
    cin >> n;
    for(int i=0 ; i<n ; ++i){
        cin >> a[i];
        v.push_back(a[i]);
    }
    sort(all(v));
    int cnt = 0;
    for(int i=0 ; i<n ; ++i){
        if(a[i] != v[i])cnt++;
    }
    if(cnt > 2)
        puts("NO");
    else
        puts("YES");
}

Measured memory_bytes: 256
import java.util.Scanner;

/*
問題文

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();

		long a = n%k;
		long ans = 0;
		if( n%k==0 ){
			ans = 0;
		}else{
			ans = Math.min(a, k-a);
		}
		System.out.println(ans);
    }
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC126C()
{
	int N, K;
	cin >> N >> K;
		double x = static_cast<double>(max(0,N-K + 1)) / N;
		double y = 1.0 - x;
		for (int i = 1; i < min(K,N+1); ++i)
		{
			double p = 1.0 / N;
			int j = i;
			while (j < K)
			{
				p *= 0.5;
				j *= 2;
			}
			x += p;
		}
		cout << std::fixed << std::setprecision(30) << x << endl;
}


int main()
{
	ABC126C();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int a, b, m = 0, ans = 0;
  
  for(int i = 0; i < M; ++i){
    cin >> a >> b;
    ans += max(0,N-a);
    m = max(N-a,m);
  }
  ans -= m;
  cout << ans << endl;
  return 0;
}

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

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

    int ret = 0;
    if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R') {
        ret = 3;
    } else if ((S[0] == 'R' && S[1] == 'R')
            || (S[1] == 'R' && S[2] == 'R')) {
        ret = 2;
    } else if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R') {
        ret = 1;
    }

    cout << ret << endl;
}


Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int N = Integer.parseInt(br.readLine());
        String A = br.readLine();
        String B = br.readLine();
        String C = br.readLine();
        int ans = 0;
        for (int i = 0; i < N; i++) {
            char a = A.charAt(i);
            char b = B.charAt(i);
            char c = C.charAt(i);
            if (a == b && b == c) {
                // do nothing
            } else if (a == b || b == c || c == a) {
                ans++;
            } else {
                ans += 2;
            }
        }
        out.println(ans);
        out.close();
    }
}


Measured memory_bytes: 21204
<?php
$array = explode(" ", trim(fgets(STDIN)));

$min = 10**10;
for($i = -2; $i <= 52;$i++){
    $sum = 0;
    foreach($array as $v){
        if($i > $v){
            if(($i - $v) % 2 == 1){
                $v--;
                $sum++;
            }
            $sum+=($i - $v)/2;
        }else{
            $sum+=$v-$i;
        }
    }
    $min = min($sum, $min);
}
echo $min;

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

public class Main {
	public static void main(String[] args) {
		FastScanner FastScanner = new FastScanner();
		StringBuilder s = new StringBuilder(FastScanner.next());
		StringBuilder s1 = new StringBuilder();
		StringBuilder s2 = new StringBuilder();
		int q = FastScanner.nextInt();
		boolean isreversed = false;
		for (int i = 0; i < q; i++) {
			int t = FastScanner.nextInt();
			if (t == 1) {
				isreversed = !isreversed;
			} else {
				int f = FastScanner.nextInt();
				String c = FastScanner.next();
				if (f == 1) {
					if (isreversed)
						s1.append(c);
					else
						s2.append(c);
				} else {
					if (isreversed)
						s2.append(c);
					else
						s1.append(c);
				}
			}
		}
		s.append(s1);
		s.insert(0, s2.reverse());
		if (isreversed)
			s = s.reverse();
		System.out.println(s.toString());
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 41800
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();

    int count = k;
    String YorN = "No";
    while(a >= b && count > 0) {
      b = b*2;
      count--;
    }
    while(b >= c & count > 0) {
      c = c*2;
      count--;
    }
    if(a < b && b < c) YorN = "Yes";
    System.out.println(YorN);
  }
}

Measured memory_bytes: 35672
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut a: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        a.push(read::<String>().chars().collect());
    }
    let mut b: Vec<Vec<char>> = Vec::new();
    for _ in 0..m {
        b.push(read::<String>().chars().collect());
    }

    let mut ans = false;
    'outer: for x in 0..=(n - m) {
        'inner: for y in 0..=(n - m) {
            let mut temp_match = true;
            for i in 0..m {
                for j in 0..m {
                    if a[x + i][y + j] != b[i][j] {
                        temp_match = false
                    }
                }
            }
            if temp_match {
                ans = true;
                break 'outer;
            }
        }
    }

    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2068
//
//  main.cpp
//  Airport_Bus
//
//  Created by Uttam Datta on 31/05/19.
//  Copyright © 2019 Uttam Datta. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

vector <int> A;
int size,k, N;

int ans(){
    sort(A.begin(), A.end());
    int i = 1, c = 1;
    int j = 0;
    int buses = 1;
    while(i < N){
        if(A[j]+k >= A[i] && c < size){
            c++;
        }else{
            j = i;
            buses++;
            c = 1;
        }
        i++; 
    }
    
    return buses;
}

int main(){
    cin >> N >> size >> k;
    A.clear();
    A.resize(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cout << ans() << endl;
    return 0;
}


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

typedef long long lint;
typedef long double louble;
template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return b<a?a:b;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	char buf[bufl],*s=buf,*t=buf;
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007 , mo = 1000000007;

struct sgt
{
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)

	static const int _t = _<<2;

	lint t[_t];

	inline void up(int x){t[x]=(t[lc]+t[rc])%mo;}
	
	void plant(int x,int l,int r)
	{
		t[x]=0;
		if(l==r)return;
		plant(lc,l,mid),plant(rc,mid+1,r),up(x);
	}

	void change(int x,int l,int r,int tar,lint dlt)
	{
		if(l==r){t[x]=(t[x]+dlt)%mo;return;}
		if(tar<=mid)change(lc,l,mid,tar,dlt);
		else change(rc,mid+1,r,tar,dlt);
		up(x);
	}

	lint finder(int x,int l,int r,int tl,int tr)
	{
		if(tl<=l && r<=tr)return t[x];
		if(tr<=mid)return finder(lc,l,mid,tl,tr);
		if(tl>mid)return finder(rc,mid+1,r,tl,tr);
		return (finder(lc,l,mid,tl,tr)+finder(rc,mid+1,r,tl,tr))%mo;
	}
	
#undef lc
#undef rc
#undef mid
}t;

struct cxk
{
	int loc,spd;
	cxk(int _loc=0,int _spd=0){loc=_loc,spd=_spd;}
	inline friend int operator < (cxk a,cxk b){return a.spd<b.spd;}
}p[_];

int n,stk[_],top,ll[_],rr[_];
vector<int> got[_];

int main()
{
	n=ty();
	for(int i=1,a,b;i<=n;i++)a=ty(),b=ty(),p[i]=cxk(a,b);
	sort(p+1,p+n+1);

	top=0;
	for(int i=1;i<=n;i++)
	{
		int l=1,r=top,ans=i;
		while(r>=l)
		{
			int mid=(l+r)>>1;
			if(p[stk[mid]].loc>p[i].loc)ans=stk[mid],r=mid-1;
			else l=mid+1;
		}
		ll[i]=ans;
		if(top<=0 || p[i].loc>p[stk[top]].loc)stk[++top]=i;
	}

	top=0;
	for(int i=n;i>=1;i--)
	{
		int l=1,r=top,ans=i;
		while(r>=l)
		{
			int mid=(l+r)>>1;
			if(p[stk[mid]].loc<p[i].loc)ans=stk[mid],r=mid-1;
			else l=mid+1;
		}
		rr[i]=ans;
		if(top<=0 || p[i].loc<p[stk[top]].loc)stk[++top]=i;
	}

	for(int i=1;i<=n;i++)got[ll[i]].push_back(rr[i]);
	for(int i=1;i<=n;i++)sort(got[i].begin(),got[i].end());

	t.plant(1,0,n),t.change(1,0,n,0,1);
	for(int i=1;i<=n;i++)
		for(auto j:got[i])
			t.change(1,0,n,j,t.finder(1,0,n,i-1,n));

	printf("%lld\n",t.finder(1,0,n,n,n));

	return 0;
}


Measured memory_bytes: 20864
import java.util.*;
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    String reS = S.replace("ABC","");
    int ans = (S.length() - reS.length())/3;

    System.out.println(ans);
  }
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
  int N,M,X,Y;
  scanf("%d%d%d%d",&N,&M,&X,&Y);
  int x[N+1];
  int y[M+1];
  int i;
  for(i=0;i<N;i++){
    scanf("%d",&x[i]);
  }
  for(i=0;i<M;i++){
    scanf("%d",&y[i]);
  }
  x[N]=X;
  y[M]=Y;
  qsort(x, N+1, sizeof(int), compare_int);
  qsort(y, M+1, sizeof(int), compare_int);
  if(x[N]<y[0]){
    printf("No War");
  }else{
    printf("War");
  }
  return 0;
}


Measured memory_bytes: 128
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(l[k-1])


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
using namespace std;
int a[200010],n;
int main()
{
	cin>>n;int i,x,y;
	x=n-1;y=0;
	for(i=0;i<n;i++)
	cin>>a[i];
	if(n%2==0)
	{
		while(x>=0)
		{
		cout<<a[x]<<" ";
	    x-=2;
	}
	while(y<n)
	{
		cout<<a[y]<<" ";
		y+=2;
	}
	}
	else
	{
		x=n-1;y=1;
		while(x>=0)
		{
			cout<<a[x]<<" ";
			x-=2;
		}
		while(y<n)
		{
			cout<<a[y]<<" ";
			y+=2;
		}
	}
	return 0;
}

Measured memory_bytes: 3072
def solve():
    mod=998244353
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    sumA=sum(A)
    sumA2=(sumA+1)//2

    dp = [[0]*(sumA2+2) for i in range(N+1)]
    dp[0][0]=1
    for i in range(N):
        for j in range(sumA2+1):
            if dp[i][j]!=0:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mod
                j2=min(sumA2,j+A[i])
                dp[i+1][j2]=(dp[i+1][j2]+dp[i][j])%mod
    ans=1
    for i in range(N):
        ans=(ans*3)%mod
    ans=(ans+mod-3*dp[N][sumA2])%mod

    if sumA%2==0:
        dp = [[0]*(sumA2+2) for i in range(N+1)]
        dp[0][0]=1
        for i in range(N):
            for j in range(sumA2+2):
                if dp[i][j]!=0:
                    dp[i+1][j]+=dp[i][j]
                    j2=min(sumA2+1,j+A[i])
                    dp[i+1][j2]+=dp[i][j]
        ans=(ans+3*dp[N][sumA2])%mod

    return ans

print(solve())


Measured memory_bytes: 492936
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define LLINF (1LL<<60)
#define INF (1<<30)
#define F first
#define S second
int main(void){
    long long a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]+a[1]==a[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		
		long min = 999999999;
		long max = -999999999;
		int miner = -1;
		int maxer = -1;
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextLong();
			
			if(a[i]<min)
			{
				miner=i;
				min=a[i];
			}
			if(a[i]>max)
			{
				maxer=i;
				max=a[i];
			}
		}
		
		int ops = 0;
		StringBuilder sb = new StringBuilder();
		boolean allpos = false;
		if(max >= 0 && min >= 0)allpos = true;
		//mixed case
		if(min < 0 && max > 0 && max >= -min)
		{ //absolute largest is positive
			for(int i = 0; i < n; i++)
			{
				int id = i+1;
				if(i!=maxer)
				{
					sb.append((maxer+1) + " " + id + "\n");
					ops++;
				}
			}
			allpos = true;
		}
		else if(min < 0 && max > 0 && -min > max)
		{ //absolute largest is neg
			for(int i = 0; i < n; i++)
			{
				int id = i+1;
				if(i!=miner)
				{
					sb.append((miner+1) + " " + id + "\n");
					ops++;
				}
			}
			allpos = false;
		}
		
		if(allpos)
		{
			for(int i = 0; i < n-1; i++)
			{
				sb.append((i+1) + " " + (i+2) + "\n");
				ops++;
			}
		}
		else {
			for(int i = n-1; i>=1; i--)
			{
				sb.append((i+1) + " " + (i) + "\n");
				ops++;
			}
		}
		System.out.println(ops);
		System.out.print(sb);
		
	}

}


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

int main(){
	int N; cin >> N;
	int *V = new int[N];
	int *C = new int[N];

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

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (V[i] > C[i]) {
			ans += V[i] - C[i];
		}

	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S;
bool used[26];

int main(){
  cin >> S;

  int N = S.length();
  for (int i = 0; i < N; i++){
    used[S[i] - 'a'] = true;
  }

  if (N < 26){
    for (int i = 0; i < 26; i++){
      if (used[i]) continue;
      char now = 'a' + i;
      S += now;
      cout << S << endl;
      return 0;
    }
  }

  fill(used, used + 26, false);

  for (int i = 25; i >= 1; i--){
    used[S[i]-'a'] = true;
    if (S[i - 1] > S[i]) continue;
    
  
    for (int j = 0; j < i-1; j++) cout << S[j];
    
    int now = S[i-1] - 'a'; 
    for (int j = now; j < 26; j++){
      if (!used[j]) continue;
      char C = j + 'a';
      cout << C << endl;
      return 0;
  }
  }

  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3640
<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner();
$a = $sc->nextInt();
$b = $a/1000;
$c = ceil($b);
$d = ($c * 1000) - $a;
//out::println($b);
//out::println($c);
out::println($d);

Measured memory_bytes: 15716
//not elegant

#include <iostream>
#include <cstring>
using namespace std;

int main(void){
  int c[200][3];
  int n; cin >> n;
  for(int i=0; i<n; i++){
    for(int j=0; j<3; j++){
      cin >> c[i][j];
    }
  }
  for(int i=0; i<n; i++){
    int p = 0;
    for(int j=0; j<3; j++){
      int num = 0;
      for(int k=0; k<n; k++) if(c[i][j] == c[k][j]) num++;
      if(num == 1) p += c[i][j];
    }
    cout << p << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int a,b,c;
    cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0)cout<<0;
    else
    {
        long long int ans=min({a*b,b*c,a*c});
        cout<<ans;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(ll i = a ; i <=n;++i)
#define sf(n) scanf("%lld",&n)
#define pf(n) printf("%lld\n",n)
#define bug printf("bug\n")
#define pi 3.14159265

int main(){
ll n , x ;
sf(n);
sf(x);
ll a[n+2];
ll mi = INFINITY;
rep(i,0,n - 1) {sf(a[i]);x-=a[i];mi = min(mi, a[i]);}
ll ans = n + (x/mi);
pf(ans);

return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

N,M = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
S = [1]+[0]*(N-1)
flg = True
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if d[s] > 0 and S[s] != c:
        flg = False
    S[s] = c
    d[s] += 1

if M == 0 and N == 1:
    print(0)
    exit()
if not flg:
    print(-1)
    exit()
if S[0] == 0:
    if len(S) == 1:
        print(*S)
    else:
        print(-1)
    exit()
print("".join([str(s) for s in S]))




Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int nbElem; cin >> nbElem;
	ll shiftCost; cin >> shiftCost;
	vector<ll> vec(nbElem);
	for (int i = 0; i < nbElem; ++i) {
		cin >> vec[i];
	}

	ll res = 1e18;
	vector<vector<ll>> costTake(nbElem, vector<ll>(nbElem, 1e18));
	for (int x = 0; x < nbElem; ++x) {
		for (int i = 0; i < nbElem; ++i) {
			chmin(costTake[x][(i+x)%nbElem], vec[i]);
		}
		ll sub = shiftCost*x;
		for (int i = 0; i < nbElem; ++i) {
			if (x > 0) chmin(costTake[x][i], costTake[x-1][i]);		
			sub += costTake[x][i];
		}
		chmin(res, sub);
	}
	cout << res << "\n";
}


Measured memory_bytes: 34548
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <limits>
#include <type_traits>
using _loop_int = 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--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


// Connected component(DFS)
void dfs(int n, int comp[], vector<int> G[]) {
  int i, j, vertex, neighbor, color[100000];
  REP(i, 100000) color[i] = 0;
  stack<int> S;

  for (i = 0; i < n; i++) color[i] = 0;

  for (i = 0; i < n; i++) {
    if (color[i] == 0) {

      S.push(i);
      while (!S.empty()) {
        vertex = S.top();
        S.pop();
        color[vertex] = 1;
        comp[vertex] = i;
        for (j = 0; j < (int) G[vertex].size(); j++) {
          neighbor = G[vertex][j];
          if (color[neighbor] == 0) S.push(neighbor);
        }
      }
    }
  }
}


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N, 1) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
          par[i] = i;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        siz[ry] += siz[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
      return siz[root(x)];
    }
};

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;

  int ans[N-1];
  REP(i, N-1) ans[i] = 0;

  for(int i=1;i<N;i++){
    for(int j=i+1;j<N+1;j++){
      if(j<X){
        ans[j-i-1]++;
      } else if(i<X & j<Y+1){
        ans[X-i + min(Y-j+1, j-X)-1]++;
      } else if(i<X){
        ans[j-i - (Y-X)]++;
      } else if(j<Y+1){
        ans[min(j-X, Y-X+1 - (j-X))-1]++;
      } else if(i < Y+1){
        ans[j-Y + min(Y-X+1 - (Y-i), Y-i)-1]++;
      } else {
        ans[j-i-1]++;
      }
    }
  }

  REP(i, N-1) cout << ans[i] << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl

int main ()
{
    int a, b;
    cin >> a >> b;
    if(a > 9 or b > 9) cout << -1 << endl;
    else cout << a * b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<long long> L(87,0);
    L[0]=2;
    L[1]=1;
    int N;
    cin>>N;
    for(int i=2;i<=N;i++){
        L[i]=L[i-2]+L[i-1];
    }
    cout<<L[N]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point
{
public:
	double x, y;
	Point(double X = 0, double Y = 0)
	{
		x = X;
		y = Y;
	}
	Point operator +(const Point &p)const { return Point(x + p.x, y + p.y); };
	Point operator -(const Point &p)const { return Point(x - p.x, y - p.y); };
	Point operator *(const double a)const { return Point(x*a, y*a); };
	Point operator /(const double a)const { return Point(x / a, y / a); };
	double norm()const { return x*x + y*y; };
	double length()const { return sqrt(norm()); };
	double dot(const Point &p)const { return x*p.x + y*p.y; };
	double cross(const Point &p)const { return x*p.y - y*p.x; };
	bool operator ==(const Point &p)const
	{
		return fabs(x - p.x)<EPS &&fabs(y - p.y)<EPS;
	}
};
typedef Point Vector;

class Segment
{
public:
	Point p1, p2;
	bool IsOrthogonal(const Segment &s)
	{
		Point t1 = p2 - p1;
		Point t2 = s.p2 - s.p1;
		return equals(0.0, t1.dot(t2));
	}
	bool IsParallel(const Segment &s)
	{
		Point t1 = p2 - p1;
		Point t2 = s.p2 - s.p1;
		return equals(0.0, t1.cross(t2));
	}
};
typedef Segment Line;

int main()
{
	int q;
	cin >> q;
	REP(i, q)
	{
		int ans = 0;
		Line s1, s2;
		cin >> s1.p1.x >> s1.p1.y >> s1.p2.x >> s1.p2.y >> s2.p1.x >> s2.p1.y >> s2.p2.x >> s2.p2.y;
		if (s1.IsOrthogonal(s2))ans = 1;
		else if (s1.IsParallel(s2))ans = 2;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3212
#include <stdio.h>
#include<string.h>

int main(void){
    int N = 0;
    int c = 0;
    scanf("%d", &N);
    char S[N];
  
    scanf("%s", S);
    for(int j = 0; j < N - 1; j++){
        if (S[j]!=S[j + 1]){
            c++;
        }
    }     
    printf("%d\n", c + 1);
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a,b,c string
	fmt.Scan(&a,&b,&c)

	as := strings.Split(a,"")
	bs := strings.Split(b,"")
	cs := strings.Split(c,"")

	fmt.Println(strings.ToUpper(as[0])+strings.ToUpper(bs[0])+strings.ToUpper(cs[0]))
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll


int t, n, m, k, a[300010], q, l, r;


int32_t main(){
INIT
cin>>n;
int cnt=0;
for(int i=1; i<=n; i++){
    cin>>a[i];
    if( ( (i%2)==1 ) && ( ( a[i]%2)==1 ) ){cnt++;}
}
cout<<cnt;
return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#define rg register
#define il inline
#define ll long long
#define maxn 500005
using namespace std;
il int read(){rg int x = 0 ,w = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-') w = -1;ch = getchar();}while (ch >= '0' && ch <= '9'){x = (x<<3) + (x<<1) + ch - '0';ch = getchar();}return x * w;}
struct edge{
	int to,next;	
}e[maxn << 1];
int head[maxn] , cnt , dis[maxn];
bool vis[300][300];
char ch[300][300];
int main(){
	rg int a = read() , b = read();
	char tmp;
	for (rg int i = 1; i <= a;++i)
			scanf("%s",ch[i]);	
	for (rg int i = 1;i <= a;++i){
		bool ok = 1;
		for (rg int j = 0;j < b;++j){
			if (ch[i][j] != '.'){
				ok = 0;break;
			}
		}
		if (!ok) continue;
		for (rg int j = 0;j < b;++j){
			vis[i][j] = 1;
		}
	}
	for (rg int j = 0;j < b;++j){
		bool ok = 1;
		for (rg int i = 1;i <= a;++i){
			if (ch[i][j] != '.'){
				ok = 0;break;
			}
		}	
		if (!ok) continue;
		for (rg int i = 1;i <= a;++i){
			vis[i][j] = 1;
		}
	}
	for (rg int i = 1;i <= a;++i){
		bool ok = 0;
		for (rg int j = 0;j < b;++j)
				if (!vis[i][j]) {cout<<ch[i][j]; ok = 1;}
		if (ok) putchar('\n');			
	}	
	return 0;	
}

Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

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


	printf("%c%c%c", a[0] - 'a' + 'A', b[0] - 'a' + 'A', c[0] - 'a' + 'A');
	return 0;
}

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

int main() {
	int n, p[100010], ichi = 0, ni = 0, i = 1;
	cin >> n;
	p[n + 1] = 0;
	while (i <= n) {
	    cin >> p[i];
	    if (p[i] == i) {
	        i++;
	        cin >> p[i];
	        if (p[i] == i) ni++;
	        else ichi++;
	        i++;
	    }
	    else i++;
	}
	cout << ichi + ni;
	return 0;
}


Measured memory_bytes: 640