akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = int(readline())
    INF = 10**9
    A = tuple(map(int, readline().split()))
    B = tuple(range(1, N+1))
    def check(N, A, N1):
        que = [(0, A)]
        dist = {A: 0}
        S = [A]
        B = list(A)
        for cost in range(N1):
            T = []
            for v in S:
                if dist[v] < cost:
                    continue
                for i in range(N):
                    B[:] = v
                    for j in range(i+1, N):
                        B[i:j+1] = reversed(v[i:j+1])
                        key = tuple(B)
                        if cost+1 < dist.get(key, N1+1):
                            dist[key] = cost+1
                            T.append(key)
            S = T
        return dist
    D0 = check(N, A, (N-1)//2)
    D1 = check(N, B, (N-1)//2)
    ans = N-1
    for state, v in D0.items():
        if state in D1:
            ans = min(ans, v + D1[state])
    write("%d\n" % ans)
solve()


Measured memory_bytes: 101936
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, i, ans=1, now, nowd; cin >> N; int X[N], L[N];
vector< pair<int, int> > V; 
for(i=0; i<N; i++){ cin >> X[i] >> L[i]; V.push_back(make_pair(X[i], L[i])); }
sort(V.begin(), V.end());
int len=V.size();
for(now=0, i=1; i<len; i++){
nowd=V[now].first+V[now].second;
if(nowd<=V[i].first-V[i].second){ ans++; now=i; continue; }
if(nowd<=V[i].first+V[i].second){ continue; }
now=i;
}
cout << ans << "\n";
}

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

int sw[2019][2019] = {0};
int sh[2019][2019] = {0};

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h + 2);
    rep(i, h)
    {
        string t;
        cin >> t;
        s[i + 1] = '#' + t + '#';
    }
    rep(i, w + 2)
    {
        s[0].push_back('#');
        s[h + 1].push_back('#');
    }

    forx(i, 1, h + 1)
    {
        int bf = 0;
        forx(j, 0, w + 2)
        {
            if (s[i][j] == '#')
            {
                sw[i][j] = 0;
                forx(k, bf, j) sw[i][k] = j - bf;
                bf = j + 1;
            }
        }
    }

    forx(j, 1, w + 1)
    {
        int bf = 0;
        forx(i, 0, h + 2)
        {
            if (s[i][j] == '#')
            {
                sh[i][j] = 0;
                forx(k, bf, i) sh[k][j] = i - bf;
                bf = i + 1;
            }
        }
    }

    int ans = 0;
    forx(i, 1, h + 1) forx(j, 1, w + 1) if (sw[i][j] != 0 && sh[i][j] != 0) ans = max(ans, sw[i][j] + sh[i][j] - 1);
    cout << ans << endl;
}


Measured memory_bytes: 39936
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",&s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define sz(x) x.size()
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;

// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<ii> vii;

template <typename T>
T modpow(T base, T exp, T modulus)
{
    base %= modulus;
    T result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = (result * base) % modulus;
        base = (base * base) % modulus;
        exp >>= 1;
    }
    return result;
}

ll lcm(ll a, ll b) { return (a * (b / __gcd(a, b))); }

// Some contants
const ll inf = 1e12 + 7;
const double eps = 1e-9;
const long double pi = 1.00 * acos(-1.00);


int n, a, b, c;    

void solve(){

   if( a + b - c > n || (n - (a+b-c)) > n){
       printf("IMPOSSIBLE\n");
       return;
   }

   rep(a-c){
       printf("%d ", 2);
   }
   rep(c){
       printf("%d ", n);
   }
   rep(n - (a+b-c)){
       printf("%d ", 1);
   }
   rep(b-c){
       printf("%d ", 2);
   }
   

   printf("\n");

}

int main()
{

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

    /*

    #ifndef ONLINE_JUDGE
        freopen("./input.txt", "r", stdin);
        freopen("./output.txt", "w", stdout);
    #endif
    */

    int d, s, t;
    cin >> d >> t >> s;
    if(s*t >= d){
        cout << "Yes" << endl;
    }else{
        cout << "No\n";
    }

    return 0;
}



Measured memory_bytes: 3652
/**
 *    author:  tourist
 *    created: 04.01.2020 01:50:49       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long c;
  cin >> n >> c;
  vector<long long> x(n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long ans = 0;
  for (int rot = 0; rot < 2; rot++) {
    long long sum_p = 0;
    for (int i = 0; i < n; i++) {
      sum_p += v[i];
    }
    long long max_s = 0;
    long long sum_s = 0;
    for (int i = n - 1; i >= -1; i--) {
      long long cur = sum_p - (i >= 0 ? x[i] : 0);
      ans = max(ans, cur + max_s);
      if (i >= 0) {
        sum_s += v[i];
        max_s = max(max_s, sum_s - 2 * (c - x[i]));
        sum_p -= v[i];
      }
    }
    for (int i = 0; i < n; i++) {
      x[i] = c - x[i];
    }
    reverse(x.begin(), x.end());
    reverse(v.begin(), v.end());
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


ll get_num(string num, int x)
{
	if (num[0] == 'X' && x == 0 && num.length() >= 2) return -99999999999999999999;
	ll ret = 0;
	rep(i, num.length())
	{
		if (num[i] == 'X')
		{
			ret = ret * 10 + x;
		} else {
			ret = ret * 10 + num[i] - '0';
		}
	}
	return ret;
}


int main()
{
	string inp, a, b, c;
	
	while (cin >> inp)
	{
		a = inp.substr(0, inp.find("+"));
		b = inp.substr(inp.find("+") + 1, inp.find("=") - inp.find("+") - 1);
		c = inp.substr(inp.find("=") + 1);
		
		bool flag = false;
		rep(i, 10)
		{
			if (get_num(a, i) == -99999999999999999999 || get_num(b, i) == -99999999999999999999 || get_num(c, i) == -99999999999999999999)
				continue;
			if (get_num(a, i) + get_num(b, i) == get_num(c, i))
			{
				cout << i << endl;
				flag = true;
				break;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

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

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

public class Solve
{
    static void Main(string[] args)
    {
        new ABC_A();
    }
}
public class ABC_A
{
    public ABC_A()
    {
        var inn=Ex.ReadIntArray();
        int n = inn[0];
        int m = inn[1];
        Console.WriteLine(n*(n-1)/2+m*(m-1)/2);
    }
}
public class ABC_B
{
    public ABC_B()
    {

    }
}
public class ABC_C
{
    public ABC_C()
    {

    }
}
public class ABC_D
{
    public ABC_D()
    {

    }
}
public class ABC_E
{
    public ABC_E()
    {

    }
}
public class ABC_F
{
    public ABC_F()
    {

    }
}
public static class Ex
{
    public static string Read { get { return Console.ReadLine().Trim(); } }
    public static int ReadInt { get { return int.Parse(Read); } }
    public static long ReadLong { get { return long.Parse(Read); } }
    public static double ReadDouble { get { return double.Parse(Read); } }
    public static string[] ReadArray() { return Read.Split(' '); }
    public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
    public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
    public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

Measured memory_bytes: 13396
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = I()
v = 10**9
x = (v - s%v) % v
y = (s + x)//v
print(0,0,10**9,1,x,y)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
double a[100];
bool cmp(double x,double y){
	return x>y;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}	
	sort(a,a+n,cmp);
	int k=n-2;
	double ans=0;
	while(k>=0){
		ans=(a[k]+a[k+1])/2;
		a[k]=ans;
		k--;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
int mark[N],pr[N],cnt;
int p[20],c;

void init(int n){
	rep(i,2,n){
		if(mark[i]) continue;
		pr[++cnt]=i;
		for(int j=i;j<=n;j+=i) mark[j]=1;
	}
}

int getphi(int x){
	int res=1;
	rep(i,1,c) if(x%p[i]==0){
		res*=p[i]-1,x/=p[i];
		while(x%p[i]==0) x/=p[i],res*=p[i];
	}
	return res;
}

int power(int x,ll p,int m){
	int res=1;
	for(;p;p>>=1,x=(ll)x*x%m)
		if(p&1)res=(ll)res*x%m;
	return res;
}

int gcd(int a,int b,int &x,int &y){
	if(!b) return x=1,y=0,a;
	int r=gcd(b,a%b,y,x);
	return y-=a/b*x,r;
}

ll solve(int a,int m){
	if(m==1) return 1;
	int n=getphi(m),g=__gcd(m,n);
	int u=solve(a,g),v=power(a,u,m);
	int x,y,c=v-u,t=gcd(n,m,x,y);
	ll X=(ll)x*c/t%m,mod=(ll)m*n;
	return (ll)(n*X+u+mod)%mod+mod;
}

void rmain(){
	int a,m,t;
	read(a),read(m),a%=m;
	int g=__gcd(a,m);
	t=m,c=0;
	for(int i=1;pr[i]*pr[i]<=t;i++)
		if(t%pr[i]==0){
			p[++c]=pr[i];
			while(t%pr[i]==0) t/=pr[i];
		}
	if(t>=2) p[++c]=t;
	ll res=solve(a,m);
	assert(power(a,res,m)==res%m);
	cout<<res<<endl;
}

signed main(){
	int T; read(T); init(100000);
	while(T--) rmain();
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//
 
string s;
int dp[212345];
 
int main() {
	cin >> s;
	int N = s.size();
	REP(i, N) s[i] -= 'a';
	
	map<int, int> m;
	
	fill(dp, dp + N + 1, INF);
	int x = 0;
	dp[0] = 0; m[0] = 0;
	REP(i, N) {
		x ^= 1<<s[i];
		int res = INF;
		
		if (m.find(x) != m.end()) chmin(res, m[x] + 1);
		REP(j, 26) if (m.find(x ^ 1<<j) != m.end()) chmin(res, m[x ^ 1<<j] + 1);
		
		if (m.find(x) == m.end() || m[x] > res) m[x] = res;
		dp[i + 1] = res;
	}
	cout << dp[N] << endl;
	
	return 0;
}

Measured memory_bytes: 10628
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
	int count;
	if (n < 10) {
		count = n;
	} else {
		count = 9;
		if (n >= 100 && n < 1000) {
			count += n-99;
		}
		if (n >= 1000) {
			count += 999-99;
			if (n >= 10000 && n < 100000) {
				count += n-9999;
			}
			if (n == 100000) {
				count += 99999-9999;
			}
		}
	}

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

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

bool lunlunhantei(ll n){
    string s=to_string(n);
    int size=s.length();
    for(int i=1;i<size;i++){
        if(s[i]-s[i-1]>=2)return false;
        else if((s[i]=='9'&&s[i-1]=='0')||(s[i]=='0'&&s[i-1]=='9'))return false;
    }
    return true;
}

ll nextlunlun(ll n){
    if(lunlunhantei(n+1)){
        return n+1;
    }else{
        int e=1,d=10;
        while(!lunlunhantei((n+d)/d)){
            e++;
            d*=10;
        }
        string s=to_string((n+d)/d);
        for(int i=0;i<e;i++){
            if(s[s.length()-1]-1>='0')s.push_back((char)(s[s.length()-1]-1));
            else s.push_back('0');
        }
        ll ans=stoll(s);
        return ans;
    }
}

int main(){
    INT(k);
    ll ans=0;
    for(int i=0;i<k;i++){
        ans=nextlunlun(ans);
    }
    out(ans);
}

Measured memory_bytes: 3776
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;
ll inf = 1e9;
//LLONG_MIN

//AC

int main(void){
	ll a,N,ans=0;
	cin>>N;
	rep(i,N){
		cin>>a;
		while(a%2==0){
			a/=2;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  string s,t;
  cin>>s>>t;
 
  if(s==t){
    cout<<"Yes"<<endl;
    return 0;
  }
 
 
  rep(i,s.size()){
     vector<char> C;
     rep(i,s.size())
    C.push_back(s[i]);
    char dummy=C[s.size()-1];
    C.pop_back();
    s[0]=dummy;
    rep(i,C.size())
      s[i+1]=C[i];
    // cout<<"s=="<<s<<"dummy"<<dummy<<endl;
     if(s==t){
    cout<<"Yes"<<endl;
    return 0;
    }
  }
  
  cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import itertools

N,M,Q = map(int,input().split())

# nullで初期化
abcd = [None] * Q
for i in range(Q):
  abcd[i] = list(map(int,input().split()))

ans = 0
# itertools.combinations_with_replacement(イテラブル,組み合わせの数)
for list in list(map(list, itertools.combinations_with_replacement(range(1,M+1), N))):
  num = 0
  for x in abcd:
    if list[x[1]-1] - list[x[0]-1] == x[2]:
      num += x[3]
  ans = max(ans,num)
print(ans)

Measured memory_bytes: 23124
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
    int64_t x, y;
    cin >> x >> y;
    vector<int64_t> list;

    int64_t num = y / x;
    int64_t cnt = 1;
    int64_t qt = 2;
    if (qt > num)
    {
        cout << 1 << endl;
        return 0;
    }
    while (num >= qt)
    {
        list.push_back(qt);
        qt *= 2;
    }
    int qtx = num / list.at(list.size() - 1);
    cnt += qtx * (list.size());
    cout << cnt << 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();
        int m = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long[] c = new long[m];
        long[] d = new long[m];
        long[] result = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            result[0] = 0;
        }
        for (int i = 0; i < m; i++) {
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            long minDis = 0;
            for (int j = 0; j < m; j++) {
                long dis = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
                if (j == 0) {
                    minDis = dis;
                    result[i] = j + 1;
                    continue;
                }
                if (dis < minDis) {
                    minDis = dis;
                    result[i] = j + 1;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(result[i]);
        }
    }

}


Measured memory_bytes: 22740
using System;
using System.Linq;

class Contest {
  static void Main() {
    var N = int.Parse(Console.ReadLine().Trim());
    var A = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();
    int[] answer = new int[N];
    
    for(var i = 0; i < N; i++) {
      answer[A[i] - 1] = i + 1;
    }
    Console.WriteLine(string.Join(" ", answer));
  }
}

Measured memory_bytes: 31836
#include <iostream>

using namespace std;

int MOD = 1e9 + 7;

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

  long dp[s.length() + 1][4];

  for (int i = s.length(); i >= 0; i--) {
    for (int j = 3; j >= 0; j--) {
      if (i == s.length()) {
        if (j == 3) {
          dp[i][j] = 1;
        } else {
          dp[i][j] = 0;
        }
      } else {
        if (s[i] == '?') {
          dp[i][j] = dp[i + 1][j] * 3;
        } else {
          dp[i][j] = dp[i + 1][j];
        }
        if (j < 3 && (s[i] == '?' || s[i] == "ABC"[j])) {
          dp[i][j] += dp[i + 1][j + 1];
        }
        dp[i][j] %= MOD;
      }
    }
  }

  cout << dp[0][0] << endl;

  return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
void dfs(int a);
int n,go[101],back[101],link[101],keep[101][101],count=1;

int main(){
  int i,j,num;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    go[i]=back[i]=0;
    scanf("%d",&num);
    scanf("%d",&link[num]);
    for(j=1;j<=link[num];j++) scanf("%d",&keep[num][j]);
  }
  for(i=1;i<=n;i++){
    if(go[i]==0)dfs(i);
  }

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,go[i],back[i]);
  }
  return 0;
}

void dfs(int a){
  int i;
  go[a]=count++;

  for(i=1;i<=link[a];i++){
    if(go[keep[a][i]]==0){
      dfs(keep[a][i]);
    }
  }
  back[a]=count++;
  
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,a;
cin >> n >> a;
n %= 500;
if(n<=a) {
  cout << "Yes" << endl;
} else {
  cout << "No" << endl;
}
return 0;
}


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

int main(){
  string S; cin >> S;
  if(S.at(2)==S.at(3)){
    if(S.at(4)==S.at(5)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
  int n;
  cin>>n;
  int x=2;
  for(int i=0;i<20;i++){
    if(n<x)
      break;
    else
      x*=2;
  }
  cout<<x/2<<endl;
  return 0;
  
}



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

long long n, m, o;
int main() {
	cin >> n >> m >> o;
	if (n % 2 == 0 || m % 2 == 0 || o % 2 == 0) cout << 0 << endl;
	else {
		cout << min({ n*m, n*o, m*o }) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner src = new Scanner(System.in);
			int W = src.nextInt();
			int H = src.nextInt();
			int x = src.nextInt();
			int y = src.nextInt();
			int r = src.nextInt();

			if(((r <= x) && (x <= W-r)) && ((r <= y) && (y <= H-r))) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
	}
}



Measured memory_bytes: 26356
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a int
	var b string

	fmt.Scan(&a, &b)

	bl := strings.Split(b, ".")
	bn, _ := strconv.Atoi(bl[0])
	bdec, _ := strconv.Atoi(bl[1])

	ans := a*bn*100 + a*bdec

	fmt.Println(ans / 100)
}


Measured memory_bytes: 1820
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int p[60];
int main(){
    int N;
    int cnt=0;
    cin >> N;
    rep(i,N){
        cin >> p[i];
        if(p[i]!=i+1){
            cnt++;
        }
    }
    if(cnt == 2 || cnt == 0){
        cout <<"YES"<<endl;
    }else{
        cout<<"NO" <<endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,m;
  cin >> n >> m;
  vec a(n),b(m);
  set<ll> ala,alb;
  for(ll i=0;i<n;i++) cin >> a[i],ala.insert(a[i]);
  for(ll i=0;i<m;i++) cin >> b[i],alb.insert(b[i]);
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(ala.size()!=n||alb.size()!=m||a[n-1]!=n*m||b[m-1]!=n*m) {
    cout << 0 << endl;
    return 0;
  }
  ll ans=1;
  for(ll i=n*m;i;i--) {
    ll ida=lower_bound(a.begin(),a.end(),i)-a.begin();
    ll idb=lower_bound(b.begin(),b.end(),i)-b.begin();
    ll v;
    if(a[ida]==i&&b[idb]==i) continue;
    else if(a[ida]==i) {
      v=m-idb;
    }
    else if(b[idb]==i) {
      v=n-ida;
    }
    else {
      v=((n-ida)*(m-idb)-(n*m-i));
      if(v<=0) ans=0;
    }
    ans=ans*v%mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3700
n=int(input())
a, b=map(int,input().split())
p=list(map(int,input().split()))
x, y, z=0, 0, 0

for i in p:
    if i<=a:
        x += 1
    elif i>=b+1:
        z += 1
    else:
        y += 1

print(min(x, y, z))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#define MAX 80001
using namespace std;

class state{
public:
  int n,ans;
  bool f;
};

int main(){
  string str;
  while(cin >> str && str != "0"){
    int an,ans;
    vector<state> v;
    state s;
    an = ans = 0;
    for(int i=0;i<str.size();i++){
      int n = str[i] - '0';
      if(n == 0){
	for(int j=0;j<v.size();j++) v[j].f = (v[j].f + 1) % 2;
	ans += an;
      }
      else{
	s.n = n;
	s.ans = 1 + an;
	s.f = false;
	an = 0;
	v.push_back(s);
	vector<state>::iterator it = v.end();
	it -= 2;

	for(int j=v.size()-2;j>=0;j--,it--){
	  if(v[j].f) v[j].n += n;
	  else v[j].n -= n;
	  v[j].f = (v[j].f + 1) % 2;

	  if(v[j].n < 0) v[j].n += 11;
	  else if(v[j].n >= 11) v[j].n -= 11;

	  if(v[j].n == 0){
	    an += v[j].ans;
	    it = v.erase(it);
	  }
	}
	ans += an;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1120
n = int(input())
s = list(input())
ans = [0 for i in range(n + 1)]

for i in range(1, n + 1):
    if s[i - 1] == "I":
        ans[i] = ans[i - 1] + 1
    else:
        ans[i] = ans[i - 1] - 1

print(max(ans))

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

int main()
{
    int n, a[10], b;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 0; i < 10; i++ )
            a[i] = 0;

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

        for( int i = 0; i < 10; i++ )
        {
            if( a[i] == 0 )
                cout << '-' << endl;
            else
            {
                for( int j = 0; j < a[i]; j++ )
                    cout << '*';
                cout << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3020
#include <iostream>

using namespace std;

int main() {
    long long N, M;

    cin >> N >> M;

    long long sum = 0;

    for(int i = 0; i < M; i++) {
        long long num;
        cin >> num;
        sum += num;
    }

    if(N >= sum) {
        cout << N - sum << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
void main() {
	auto S = rs, T = rs;
	S ~= S;
	if(S.canFind(T)) writeln("Yes");
	else writeln("No");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner scanner = new Scanner(System.in);
		int n = Integer.parseInt(scanner.nextLine());
		String[] list = scanner.nextLine().split(" ");
		int[] aaa = new int[n];

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

			aaa[i] = Integer.parseInt(list[i]);

		}

		int ans = 0;

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

			ans = Main.gcd(aaa[i], ans);


		}



		System.out.println(ans);
	}

	public static Integer gcd(int a, int b) {

		return b == 0 ? a : gcd(b, a % b);

	}
}



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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	vector<long long> prefix(n + 1), suffix(n + 1);
	for (int i = 1; i <= n; i++) {
		prefix[i] = prefix[i - 1] + a[i - 1];
	}
	for (int i = n - 1; i >= 0; i--) {
		suffix[i] = suffix[i + 1] + a[i];
	}
	long long ans = LLONG_MAX;
	for (int i = 0; i <= n; i++) {
		ans = min(ans, abs(suffix[i] - prefix[i]));
	}
	cout << ans;
}



Measured memory_bytes: 7168
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
      int X = sc.nextInt();
      int Y = sc.nextInt();
    if (Y % 2 ==0 && Y >= 2 * X && Y <= 4 * X) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 27076
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while((line = Console.ReadLine()) != null)
            {
                var a = line.Split(',').Select(int.Parse).ToArray();
                var total = a.Take(10).Sum();
                var t = (double)total / (a[10] + a[11]);
                var x = a[10] * t;
                for(int i = 0, b = 0; i < 10; i++)
                {
                    b += a[i];
                    if (b >= x)
                    {
                        Console.WriteLine(i + 1);
                        break;
                    }
                }
            }
        }
    }
}

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

int64_t total(int64_t n, int64_t x) {
  return n / x + 1;
  }

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

 if( a == 0 ){
   cout << total(b, x) << endl;
 }
 else cout << total(b, x) - total(a - 1, x) << endl;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 1000
char mat[MAXN+1][MAXN+1];
int main(){
    FILE*fi,*fout;
    int i,j,n,m;
    //fi=fopen("A.in" ,"r");
   // fout=fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d %d " ,&n,&m);
    for(i=1;i<=n;i++)
     for(j=1;j<=m;j++)
       fscanf(fi,"%c " ,&mat[i][j]);
    for(i=0;i<=n+1;i++){
      for(j=0;j<=m+1;j++)
       if(i==0||j==0||i==n+1||j==m+1)
         fprintf(fout,"#");
        else
         fprintf(fout,"%c" ,mat[i][j]);
      fprintf(fout,"\n");
    }

    //fclose(fi);
   // fclose(fout);
}


Measured memory_bytes: 764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

n, k = map(int, input().split())

#def mpow(x, n):
#    result = 1
#    while n > 0:
#        if (n & 1):
#            result = (result * x) % MOD
#        x = (x * x) % MOD
#        n >>= 1
#    return result
#
#factorial = [0] * (n + 2)
#inverse = [0] * (n + 2)
#factorial[0] = 1
#inverse[0] = 1
#
#for i in range(1, n + 2):
#    factorial[i] = (factorial[i-1] * i) % MOD
#    inverse[i] = mpow(factorial[i], MOD - 2) % MOD

ans = 0

sum_cache = [0] + [0] * n
for i in range(1, n+1):
    sum_cache[i] = sum_cache[i-1] + i

for i in range(k, n+1):
    #ans += (factorial[n+1] * inverse[n+1-i] * inverse[i]) % MOD
    ans += ((sum_cache[n] - sum_cache[n-i]) - sum_cache[i-1] + 1) % MOD
# n + 1
ans += 1

print(ans % MOD)


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

int D, N;

int cal(int x)
{
	int res = 0;
	while(x%100 == 0){
		x/=100;
		res++;
	}
	return res;
}

void solve()
{
	vector<int> ans;
	for(int i=1;;++i){
		if(cal(i) == D){
			ans.push_back(i);
			if((int)ans.size() == N){
				cout << ans.back() << '\n';
				return;
			}
		}
	}
}

int main()
{
	cin >> D >> N;
	solve();
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const int IINF = 1 << 30;

int main(int argc, char const *argv[])
{
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];
    vector<vector<int>> dp(h, vector<int>(w, IINF));
    if (g[0][0] == '#')
        dp[0][0] = 1;
    else
        dp[0][0] = 0;
    rep(i, h) rep(j, w)
    {
        if (i + 1 < h)
        {
            if (g[i + 1][j] == '#')
            {
                int tmp = dp[i][j];
                if (g[i][j] == '.')
                    tmp++;
                dp[i + 1][j] = min(dp[i + 1][j], tmp);
            }
            else
            {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            }
        }
        if (j + 1 < w)
        {
            if (g[i][j + 1] == '#')
            {
                int tmp = dp[i][j];
                if (g[i][j] == '.')
                    tmp++;
                dp[i][j + 1] = min(dp[i][j + 1], tmp);
            }
            else
            {
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
def g;gets.split.map &:to_i;end
while(m,n=g)[0]>0
a=(1..g[0]).map{|i|g+[i]}
b=(1..g[0]).map{g+[11]}
p b.map{|c|d=a+[c]
s=0
(1..n).map{|j|(1..m).map{|i|d.min_by{|x,y,t|z=(y-j).abs
[z+[(x-i).abs-(z+(i<x ?1-j%2:j%2))/2,0].max,t]}==c&&s+=1}}
s}.max
end

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

int main(){
  string str;
  getline(cin, str);
  int a[3];

  sscanf(str.c_str(), "%d %d %d", &a[0], &a[1], &a[2]);
  
  int sum5s = 0;
  int sum7s = 0;
  for(int i = 0; i < 3; i++){
  	if(a[i] == 5)
      sum5s++;
    else if(a[i] == 7)
      sum7s++;
  }
  
  if(sum5s == 2 & sum7s == 1)
    cout << "YES";
  else
    cout << "NO";
  
  return 0;
}

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

#define INF_LL 1e18
#define INF 1e9

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

using namespace std;

using ll = long long;
using PII = pair<int, int>;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	ll N, X;
	cin >> N >> X;
	ll res = N;
	N = N-X;
	if(N < X) swap(N, X);
	while(X != 0){
		res += N / X * X * 2;
		ll tmp = X;
		X = N%X;
		N = tmp;
	}
	res -= N;
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SZ 2333
using namespace std;
char A[SZ],B[SZ]; int n,ans;
int mi[SZ],ma[SZ],mx[SZ];
void work()
{
    for(int i=0;i<n;++i)
    {
        mi[i]=ma[i]=0;
        while(B[(i+ma[i])%n]!='1') ++ma[i];
        while(B[(i+mi[i]+n)%n]!='1') --mi[i];
    }
    for(int s=0;s<n;++s)
    {
        for(int r=0;r<n;++r) mx[r]=0;
        int dif=0;
        for(int r=0;r<n;++r) if(A[r]!=B[(r+s)%n])
            mx[-mi[r]]=max(mx[-mi[r]],ma[r]-s),++dif;
        int ly=0,ca=1e9;
        for(int r=n-1;r>=0;--r)
            ca=min(ca,ly+r), ly=max(ly,mx[r]);
        ans=min(ans,2*ca+s+dif);
    }
}
int main()
{
    scanf("%s%s",A,B);
    n=strlen(A); ans=1e9;
    bool ha=0,hb=0;
    for(int i=0;i<n;++i)
        if(A[i]=='1')ha=1;
    for(int i=0;i<n;++i)
        if(B[i]=='1')hb=1;
    if(!hb)
    {
        if(ha) puts("-1");
        else puts("0");
        return 0;
    }
    work(); reverse(A,A+n);
    reverse(B,B+n); work();
    printf("%d\n",ans);
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,x,y;
    cin>>a>>b;
    x=b/a;
    y=b%a;
    if(y>=1){
        cout<<x+1<<endl;
    }
    else{
        cout<<x<<endl;
    }
}



Measured memory_bytes: 3096
import java.io.PrintWriter

val squares = (1..127).map { it * it }

fun check(x: List<Int>, y: List<Int>): Boolean {
    val distanceSquared = x.zip(y).map { (it.first - it.second) * (it.first - it.second)}.sum()
    return distanceSquared in squares
}

fun solve(out: PrintWriter): Boolean = with(out) {
    val (L, R) = readLine()!!.split(" ").map { it.toInt() }

    val Lmod2019 = if ((L/2019+1) * 2019 <= R) 0 else L % 2019
    val Rmod2019 = if ((R/2019) * 2019 >= L) 2018 else R % 2019

    var m = Int.MAX_VALUE
    for (i in Lmod2019..Rmod2019) {
        for (j in i+1..Rmod2019) {
            if (m > i*j%2019)
                m = i*j%2019
        }
    }
    println(m)
    return false
}

// with(PrintWriter(System.out))
// with(File("out.txt").printWriter())
// with(File(args[1]).printWriter())
fun main(args: Array<String>) = with(PrintWriter(System.out)){
//    System.setIn(File(args[0]).inputStream())
    while(solve(this));
    flush()
}

Measured memory_bytes: 36104
#include <bits/stdc++.h>
#define N 2020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
ll a[N], b[N], x;
int main(int argc, char const *argv[]) {
  int n = read();
  x = read();
  for (int i = 0; i < n; ++ i) {
    b[i] = a[i] = read();
  }
  ll res = 1ll << 60;
  for (int len = 0; len < n; ++ len) {
    // 枚举左移位数
    for (int i = 0; i < n; ++ i) {
      b[i] = min(b[i], a[(i - len + n) % n]);
    }
    ll ans = len * x;
    for (int i = 0; i < n; ++ i) {
      ans += b[i];
    }
    res = min(res, ans);
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
const int mod = 1e9+7;

vector<int> a,b;


int main(){
    int n,m;
    cin >> n >> m;
    int num=1;
    ll ans = 1;
    bool check_a,check_b;
    a.resize(n);
    b.resize(m);

    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    rep(i,n-1){
        if(a[i] == a[i+1]){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i,m-1){
        if(b[i] == b[i+1]){
            cout << 0 << endl;
            return 0;
        }
    }
    

    int tmp = 0;
    for(int i = n-1;i >= 0; i--){
        for(int j = m-1; j >= 0; j--){

            num = i*m + j + 1;
            check_a = binary_search(a.begin(),a.end(),num);
            check_b = binary_search(b.begin(),b.end(),num);
            
            if(check_a && check_b){
                ans *= 1;
            }else if(check_a){
                tmp = b.end() - lower_bound(b.begin(),b.end(),num);
                ans = ((ans % mod) * (tmp % mod)) % mod;
            }else if(check_b){
                tmp = a.end() - lower_bound(a.begin(),a.end(),num);
                ans = ((ans % mod) * (tmp % mod)) % mod;
            }else{
                tmp = a.end() - lower_bound(a.begin(),a.end(),num);
                tmp *= (b.end()  - lower_bound(b.begin(),b.end(),num) );
                tmp = tmp-(n*m-num);
                ans = ((ans % mod) * (tmp % mod)) % mod;
            }

        }
    }

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


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


int main() {
  Int N;
  cin >> N;
  vector<string> S(N);
  vector<int> leng(N);
  set<string> ss;
  
  rep(i,N) {
    cin >> S[i];
    leng[i] = S[i].size();
    auto ite = ss.find(S[i]);
    if (ite != ss.end()) {
      cout << "No" << endl;
      return 0;
    }
    else ss.insert(S[i]);
  }
  
  bool flag = true;
  rep1(i,N-1) {
    if (S[i-1][leng[i-1]-1] != S[i][0]) flag = false;
  }
  
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())

graph = [[] for _ in range(N+1)]

for i in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (N+1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)

ans = [0] * (N+1)
while d:
    v = d.popleft()
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v]+1
        d.append(i)
        ans[i] = v

print("Yes")
print(*ans[2:], sep='\n')


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

int main() {
    int A, B;
    cin >> A >> B;

    int sum = A + B;
    if (10 <= sum) {
        cout << "error" << endl;
    } else {
        cout << sum << endl;
    }
    return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  string O, E;
  cin >> O >> E;

  rep(i, E.size()) {
    cout << O[i] << E[i];
  }
  if (O.size() > E.size()) cout << O[O.size() - 1];

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
a=[]
3.times do |i|
  a[i]=gets.split.map(&:to_i)
end
n=gets.to_i
n.times do
  b=gets.to_i
  3.times do |i|
    3.times do |j|
      if a[i][j]==b
        a[i][j]=0
      end
    end
  end
end
3.times do |i|
  if a[i][0]==0&&a[i][1]==0&&a[i][2]==0
    puts "Yes"
    exit
  end
end
3.times do |i|
  if a[0][i]==0&&a[1][i]==0&&a[2][i]==0
    puts "Yes"
    exit
  end
end
if a[0][0]==0&&a[1][1]==0&&a[2][2]==0
  puts "Yes"
  exit
end
if a[0][2]==0&&a[1][1]==0&&a[2][0]==0
  puts "Yes"
  exit
end
puts "No"



Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
	int d,n,x,menseki;
	while(scanf("%d",&d)!=EOF)
	{
		n=600/d;
		menseki=0;
		for(x=1; x<n; x++)
			menseki+=(d*x)*(d*x)*d;
		printf("%d\n",menseki);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
long long n,m,x[100001],w[100001],v[100001],rv[100001],s[100001],u[100001];
int main()
{
	int i;
	long long maxx;
    scanf("%lld%lld",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%lld%lld",&x[i],&w[i]);
        v[i]=v[i-1]+w[i];
        s[i]=max(s[i-1],v[i]-x[i]);
    }
    for(i=n;i>=1;i--)
    {
        rv[i]=rv[i+1]+w[i];
        u[i]=max(u[i+1],rv[i]-m+x[i]);
    }
    for(i=n;i>=1;i--)
    {
        maxx=max(maxx,rv[i]-2*(m-x[i])+s[i-1]);
        maxx=max(maxx,u[i]);
    }
    for(i=1;i<=n;i++)
    {
        maxx=max(maxx,v[i]-2*x[i]+u[i+1]);
        maxx=max(maxx,s[i]);
    }
    printf("%lld",maxx);
    return 0;
}

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

int main() {
    string S; cin >> S;
    ll ans = 0;
    int len = S.size();
    for (int i = 0; i < 1<<len-1; i++){
        ll a = S[0] - '0';
        for (int j = 0; j < len-1; j++){
            if(i>>j&1){
                ans += a;
                a = S[j+1] - '0';
            } else {
                a *= 10;
                int b = S[j+1] - '0';
                a += b;
            }
        }
        ans += a;
        //cout << i << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba")
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            int iC = int.Parse(sS[2]);
            int iD = int.Parse(sS[3]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Balanced";
            if (iA + iB > iC + iD) { sOut = "Left"; }
            if (iA + iB < iC + iD) { sOut = "Right"; }

            // 出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
  string s; cin >> s;
  int w; cin >> w;
  int tmp = 0;
  while (tmp < s.length()) {
    cout << s[tmp];
    tmp += w;
  }
  cout << endl;
}


Measured memory_bytes: 3536