akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string z,y="YES";
  cin>>z;
  int l=z.length();
  while(l>=5){
    if(z.substr(l-5)=="dream") z=z.substr(0,l-5);
    else if(l>=7&&z.substr(l-7)=="dreamer") z=z.substr(0,l-7);
    else if(z.substr(l-5)=="erase") z=z.substr(0,l-5);
    else if(l>=6&&z.substr(l-6)=="eraser") z=z.substr(0,l-6);
    else{y="NO"; break;}
    l=z.length();
  }
  if(l>0) cout<<"NO"<<endl;
  else cout<<y<<endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>

using namespace std;
using ll = long long;

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

	ll res = 0;
	
	int n = s.length();
	if (s == string(n, s[0])) {
		cout << n*k / 2 << endl;
		return 0;
	}

	int a1 = 0, a2 = 0;
	for (int i = 1; i<n; i++) {
		if (s[i] == s[i - 1]) {
			a1++;
			i++;
		}
	}
	for (int i = 1; i<2 * n; i++) {
		if (s[i%n] == s[(i - 1) % n]) {
			a2++;
			i++;
		}
	}

	cout << a1 + (a2 - a1)*(k - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 100010;
const int B = 20;
const int DEBUG = 0;
int dp[N][B];


int check(int a, int day) {
  REP(i, 0, B) {
    if (day & (1 << i)) {
      a = dp[a][i];
    }
  }
  return a;
}

int main(void){
  int n, l, q;
  cin >> n;
  VI x(n);
  REP(i, 0, n) {
    cin >> x[i];
  }
  cin >> l >> q;
  int cur = 0;
  // Shakutori method
  REP(i, 0, n) {
    while (cur < n && x[i] + l >= x[cur]) {
      cur++;
    }
    dp[i][0] = cur - 1;
    assert (i == n - 1 || cur - i >= 2);
    assert (cur <= n);
  }
  REP(b, 1, B) {
    REP(i, 0, n) {
      dp[i][b] = dp[dp[i][b - 1]][b - 1];
    }
  }
  if (DEBUG) {
    REP(i, 0, n) {
      cerr << "dp[" << i << "]:";
      REP(b, 0, B) {
	cerr << " " << dp[i][b];
      }
      cerr << endl;
    }
  }
  REP(i, 0, q) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (a > b) {
      swap(a, b);
    }
    int lo = 0, hi = 1 << (B - 1);
    while (hi - lo > 1) {
      int mid = (lo + hi) / 2;
      if (check(a, mid) >= b) {
	hi = mid;
      } else {
	lo = mid;
      }
    }
    cout << hi << endl;
  }
}


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

int main() {

  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) { cin >> a.at(i); }
  
  int tmp = 0;
  int t = 0;
  for(int i = 0; i < n; i++) {
    if(a.at(i) % 2 == 0) {
      tmp++;
      if(a.at(i) % 3 == 0 || a.at(i) % 5 == 0) {
        t++;
      }
    }
  }
  if(t >= tmp) {
    cout << "APPROVED" << endl;
    return 0;
  } else {
    cout << "DENIED" << endl;
    return 0;
  } 
}

Measured memory_bytes: 256
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
n=int(input())
lis=make_divisors(n)
#print(lis)
ans=float('inf')
l=len(lis)
for i in range(l//2):
    ans=min(ans,lis[i]+lis[-1*(i+1)]-2)
if l%2:
    ans=min(ans,2*(lis[l//2]-1))
print(ans)

Measured memory_bytes: 64660
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
#include<set>
using namespace std;
typedef long long int ll;
const ll MOD=10007;
const ll INF=1000000000;
const int MAX=100001;
const double EPS=1e-10;
int main(){
    int n,x;
    cin>>n>>x;
    if(x==1||x==2*n-1){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    if(n==2){
        cout<<1<<" "<<2<<" "<<3<<endl;
        return 0;
    }
    int c=1;
    if(x==2){
        for(int i=0;i<2*n-1;i++){
            if(i==(2*n-1)/2-1){
                cout<<x+1<<endl;
                continue;
            }else if(i==(2*n-1)/2){
                cout<<x<<endl;
                continue;
            }else if(i==(2*n-1)/2+1){
                cout<<x-1<<endl;
                continue;
            }else if(i==(2*n-1)/2+2){
                cout<<x+2<<endl;
                continue;
            }
            if(c!=x-1){
                cout<<c<<endl;
                c++;
            }else{
                c+=4;
                cout<<c<<endl;
                c++;
            }
        }
        return 0;
    }
    for(int i=0;i<2*n-1;i++){
        if(i==(2*n-1)/2-1){
            cout<<x-1<<endl;
            continue;
        }else if(i==(2*n-1)/2){
            cout<<x<<endl;
            continue;
        }else if(i==(2*n-1)/2+1){
            cout<<x+1<<endl;
            continue;
        }else if(i==(2*n-1)/2+2){
            cout<<x-2<<endl;
            continue;
        }
        if(c!=x-2){
            cout<<c<<endl;
            c++;
        }else{
            c+=4;
            cout<<c<<endl;
            c++;
        }
    }
}

                           


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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int notac = 0;
	vector<int> ar(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> ar[i];
	}
	for (int i = 0; i < n; ++i)
	{
		if (ar[i] != i + 1)
		{
			notac++;
		}
	}
	if (notac == 0 || notac == 2)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
long long M = 1e9+7;
long long power(long long a, long long p)
    {
        if(p==0) return 1;
        long long ans= power(a,p/2);
        ans =(ans * ans) % M;
        if(p%2) ans = (ans*a) % M;
        return ans;
    }

    bool isPrime(long long n)
    {
        if (n <= 1)
            return false;
        for (long long i = 2; i < n; i++)
            if (n % i == 0)
                return false;
        return true;
    }
    long long SieveOfEratosthenes(long long n, long long a)
    {
        bool prime[n+1];
        memset(prime, true, sizeof(prime));
        for (long long p=2; p*p<=n; p++)
        {
            if (prime[p] == true)
            {
                for (long long i=p*p; i<=n; i += p)
                    prime[i] = false;
            }
        }
        for (long long p=2; p<=n; p++)
           if (prime[p])
           {
               if(a%p==0)
               {
                   return (a-p);
               }
           }
    }
    long long nCr(int n, int r)
    {
        if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
        long long ans = 1;
        int i;
        for(i = 1; i <= r; i++) {
            ans *= n - r + i;
            ans /= i;
        }
        return ans;
    }
int main()
{
    IOS;
    double a,b,c,d,e,h,k,l,n,t,f,m,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,arr1[100001]={0},sum=0,sum1=0,ma=0,ma1=0,mi=1000000000000000001;
    long long g,co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0,sum3=0,mu=1,mu1=1;
    long long a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,b6,c1;
    double pi=2 * acos (0.0);
    string str,str1,str2,str3,str4,str5,str6;
    char ch,ch1;
    //vector<long long>v; //vector<long long> v(n+1);
    //vector<long long>v1;
    // vector<string>vs;
    // vector<string>vs1;
    vector<char>vc;
    //map<long long,long long>mp;
    map<char,int>mp1;
    //set<long long>s;
    set<long long>s1;
    queue<long long> q;
    //stack<long long> stk;
    //vector< pair<long long,long long> >v3;
    //map<long long,long long>::iterator it;
    //map<string,string>::iterator it;
    // vector<pair<char, pair<int,int> > > v3;
    //vector< pair<char,int > > v1;
    int x[]={1,1,1,0,0,-1,-1,-1};
    int y[]={0,1,-1,1,-1,1,-1,0};
    cin>>n>>a;
    vector<double>v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        sum+=v[i];
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0; i<n; i++)
    {
        if(v[i]>=(sum/(4*a)))
        {
            co++;
        }
    }
    if(co>=a)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, m;
    sc(n) sc(m)
    ll ans = 0;
    if (n > 1) ans += n * (n - 1) / 2;
    if (m > 1) ans += m * (m - 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

template <typename T>
class segmenttree
{
private:
    using F = function<T(T, T)>;
    int n;
    T dif;
    F f;
    vector<T> st;

    T query_(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
        {
            return dif;
        }

        if (a <= l && r <= b)
        {
            return st[k];
        }
        else
        {
            T x = query_(a, b, 2 * k + 1, l, (l + r) / 2);
            T y = query_(a, b, 2 * k + 2, (l + r) / 2, r);

            return f(x, y);
        }
    }

    void build()
    {
        for (int i = n - 2; i >= 0; i--)
        {
            st[i] = f(st[i * 2 + 1], st[i * 2 + 2]);
        }
    }

public:
    segmenttree(int size, T init, F f) : f(f)
    {
        n = 1;

        while (n < size)
        {
            n *= 2;
        }

        dif = init;
        st.assign(2 * n - 1, init);

        build();
    }

    void set(int i, T x)
    {
        i += n - 1;
        st[i] = x;

        while (i > 0)
        {
            i = (i - 1) / 2;
            st[i] = f(st[2 * i + 1], st[2 * i + 2]);
        }
    }

    T get(int i)
    {
        return st[i + n - 1];
    }

    T query(int a, int b)
    {
        return query_(a, b, 0, 0, n);
    }
};

//初期化例 segmenttree<bitset<26>> seg(n, 0, [](bitset<26> a, bitset<26> b) { return a | b; });

int main(void)
{
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    ll ma = 0;

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

        ma = max(ma, a[i]);
    }

    segmenttree<ll> s(ma + 1, 0, [](ll a, ll b) { return max(a, b); });

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        ll l, r;

        l = max(a[i] - k, 0ll);
        r = min(a[i] + k + 1, ma + 1);

        s.set(a[i], s.query(l, r) + 1);
        ans = max(ans, s.get(a[i]));
    }

    cout << ans << endl;
}

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

int main(){
  int N,A,B,yes=0,yesb=0;
  string S;
  cin >> N >> A >> B;
  cin >> S;
  for (int i=0;i<N;i++){
  if (S.at(i)=='a' && yes<A+B){
  cout << "Yes" << endl;
  yes++;
  }
  else if (S.at(i)=='b' && yes<A+B && yesb<B){
  cout << "Yes" << endl;
  yes++;
  yesb++;
  }
  else {
  cout << "No" << endl;
  }
  }
}

Measured memory_bytes: 896
//23, 06, 2018, 09:04:58 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, k;

    cin >> n >> k;

    int ax = 0;
    int cnt = 1;

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

        cin >> x;

        if(ax == k){
            cnt++;
            ax = 1;
        }

        ax = ax + 1;
    }

    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int e[201][201];
int vis[201];
int match[201];
int tot1=0,tot2=0;
bool find(int u)
{
	for(int i=1;i<=tot2;i++)
	{
		if(vis[i]==0&&e[u][i])
		{
			vis[i]=1;
			if(!match[i]||find(match[i]))
			{
				match[i]=u;
				return true;
			}
		}
	}
	return false;
}
bool isprime(int x)
{
	if(x==1) return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int x[201];
int odd[201];
int even[201];
signed main()
{
	int n;
	scanf("%d",&n);
	if(n==1){printf("3");return 0;}
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	for(int i=1;i<=n;i++)
	{
		if(i==1||x[i-1]!=x[i]-1)
		{
			if(x[i]%2==1) odd[++tot1]=x[i];
			else even[++tot2]=x[i];
		}
		if(i==n||x[i+1]!=x[i]+1)
		{
			if(x[i]%2==1) even[++tot2]=x[i]+1;
			else odd[++tot1]=x[i]+1;
		}
	}
	for(int i=1;i<=tot1;i++)
		for(int j=1;j<=tot2;j++)
			if(isprime(abs(odd[i]-even[j])))
				e[i][j]=1;
	int ans=0;
	for(int i=1;i<=tot1;i++)
	{
		memset(vis,0,sizeof(vis));
		if(find(i))
			ans++;
	}
	printf("%d",ans+(tot1-ans)/2*2+(tot2-ans)/2*2+(tot1-ans)%2*3);
	return 0;
}


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


using namespace std;


int h,w,d[810][810],k,sx,sy,ans=1e9;
queue<pair<int,int> > p;
string s[800];

int dx[] ={1,-1,0,0},dy[]={0,0,1,-1};


int main()
{
	cin >> h >> w >> k;
	for(int i = 0;i<h;i++)
	{
		cin >> s[i];
		for(int j=0;j<w;j++)
		{
			d[i][j] = -1;
			if(s[i][j] == 'S') sx = i,sy = j;
		}
	}
	p.push(make_pair(sx,sy));
	d[sx][sy] = k;
	while(!p.empty())
	{
		int x =p.front().first,y = p.front().second;
		p.pop();
		ans = min(ans,min(min(x,y),min(h-x-1,w-y-1)));
		if(x==0||y==0||x==h-1||y==w-1)ans=0;
		else for(int r = 0;r<4;r++)
		{
			int tx=x+dx[r],ty=y+dy[r];
			if((s[tx][ty]!='#')&&(d[tx][ty]<d[x][y]-1))
			{
				d[tx][ty]=d[x][y]-1;
				p.push(make_pair(tx,ty));
			}
		}
	}
	cout << (ans + k - 1)/k+1<<endl;
	return 0;
}

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

using namespace std;

#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

int main(void) {
    li N;
    cin >> N;

    if (N == 1) {
        cout << "Hello World";
        return 0;
    } else {
        li A, B;
        cin >> A >> B;
        cout << A + B;
        return 0;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

vector<int> connectAmida(const vector<int>& x, const vector<int>& y)
{
    int n = x.size();
    vector<int> ans(n);
    for(int i=0; i<n; ++i)
        ans[i] = y[x[i]];
    return ans;
}

vector<int> repeatAmida(int a, const vector<int>& x)
{
    int n = x.size();
    vector<int> len(n, 0);
    for(int i=0; i<n; ++i){
        int j = i;
        do{
            j = x[j];
            ++ len[j];
        }while(j != i);
    }

    vector<int> ans(n);
    for(int i=0; i<n; ++i){
        int j = i;
        for(int k=0; k<a%len[i]; ++k)
            j = x[j];
        ans[i] = j;
    }
    return ans;
}

int main()
{
    int n, k;
    cin >> n >> k;
    
    vector<int> init(n);
    for(int i=0; i<n; ++i)
        init[i] = i;

    vector<vector<int> > to(128, vector<int>(n, -1));
    for(int i=0; i<k; ++i){
        char p;
        int h;
        cin >> p >> h;

        vector<int> v = init;
        for(int y=0; y<h-1; ++y){
            for(int x=0; x<n-1; ++x){
                int g;
                cin >> g;
                if(g == 1)
                    swap(v[x], v[x+1]);
            }
        }
        for(int j=0; j<n; ++j)
            to[p][v[j]] = j;
    }

    int q;
    cin >> q;
    while(--q >= 0){
        string s;
        cin >> s;
        stack<pair<vector<int>, int> > stk;
        stk.push(make_pair(init, 1));

        unsigned k = 0;
        while(k < s.size()){
            if(s[k] == '('){
                stk.push(make_pair(init, 1));
                ++ k;
            }
            else if(s[k] == ')'){
                vector<int> v = stk.top().first;
                stk.pop();
                v = repeatAmida(stk.top().second, v);
                v = connectAmida(stk.top().first, v);
                stk.top() = make_pair(v, 1);
                ++ k;
            }
            else if(isdigit(s[k])){
                int a = 0;
                while(isdigit(s[k])){
                    a *= 10;
                    a += s[k] - '0';
                    ++ k;
                }
                stk.top().second = a;
            }
            else if(isalpha(s[k])){
                vector<int> v = to[s[k]];
                v = repeatAmida(stk.top().second, v);
                v = connectAmida(stk.top().first, v);
                stk.top() = make_pair(v, 1);
                ++ k;
            }
            else{
                ++ k;
            }
        }

        vector<int> v = stk.top().first;
        vector<int> ans(n);
        for(int i=0; i<n; ++i)
            ans[v[i]] = i + 1;

        cout << ans[0];
        for(int i=1; i<n; ++i)
            cout << ' ' << ans[i];
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1256
s = input()
k = int(input())

cnt = 0
alps = 'abcdefghijklmnopqrstuvwxyz'
for alp in alps:
    inds = []
    for i,si in enumerate(s):
        if si == alp:
            inds.append(i)
    if inds:
        s_set = set()
        for ind in inds:
            for i in range(1,6):
                if ind+i <= len(s):
                    s_set.add(s[ind:ind+i])
        sl = list(s_set)
        if cnt + len(sl) >= k:
            sl.sort()
            print(sl[k-cnt-1])
            exit()
        else:
            cnt += len(sl)


Measured memory_bytes: 68212
n = int(input())
nums = [int(num) for num in input().split()]


def solve(nums):
    nums[0] -= 1
    for i in range(1, n):
        if nums[i] > nums[i-1]:
            nums[i] -= 1
            continue
        if nums[i] < nums[i-1]:
            return 'No'
    return 'Yes'


print(solve(nums))


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

int main() {
  int64_t N;
  cin >> N;
  int64_t ans=N-1;
  for(int64_t i=1; i<=sqrt(N); i++){
    if(N%i == 0){
      if(ans > i+N/i-2) ans = i+N/i-2;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

long long M  = 1e9+7;
 
signed main(){
    fast;
    string s; cin >> s;
    if(s == "ABC")
    	cout << "ARC" << endl;
    else 
    	cout << "ABC" << endl;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N; cin >> N;
	V<int> A(N);
	rep(i, N) {
		cin >> A[i];
		A[i] -= i + 1;
	}

	sort(ALL(A));
	ll ans = 0;
	rep(i, N) {
		ans += abs(A[i] - A[N/2]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

long long expect[1001]; // LSB = 0.1
long long sum_expect[200001] = {0};
int main(void) {
	int N, K;
	cin >> N >> K;

	expect[0] = 0;
	expect[1] = 10;
	for (int i = 2; i <= 1000; i++) {
		expect[i] = expect[i-1] + 5;
	}

	for (int i = 1; i <= N; i++) {
		int p;
		cin >> p;
		sum_expect[i] = sum_expect[i-1] + expect[p];
	}

	long long ans = 0;
	for (int i = K; i <= N; i++) {
		ans = max(ans, sum_expect[i]-sum_expect[i-K]);
	}
	cout << setprecision(20) << ans/10.0 << endl;
  return 0;
}


Measured memory_bytes: 1792
// In The Name Of Allah

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

#define F first
#define S second
#define pp pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int maxx = 2e3 + 19;
const int inf = 1e18 + 19;
const int mod = 1000000007LL;

int n, x;
int a[maxx] = {}, b[maxx] = {}, ans = inf;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> x;
    for (int i = 0; i < n; i++)
        cin >> a[i], b[i] = a[i];
    for (int i = 0; i < n; i++) {
        int tmp = i * x;
        for (int j = 0; j < n; j++) {
            b[j] = min(b[j], a[(j + n - i) % n]);
            tmp += b[j];
        }
        ans = min(ans, tmp);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = [int(c) for c in input().split()]
ans = 1
MOD = 10**9+7
Cnt = Counter(A)
if N%2==1:
  for k,v in Cnt.items():
    if (k%2==0 and v==2) or (k==0 and v==1):
      ans *= v
      ans %= MOD
    else:
      print(0)
      break
  else:
    print(ans)
else:
  for k,v in Cnt.items():
    if k%2==1 and v==2:
      ans *= v
      ans %= MOD
    else:
      print(0)
      break
  else:
    print(ans)

Measured memory_bytes: 14820
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

const int mod = 1000000007;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

struct comb{
  vector<mint> fact, ifact;
  comb(int n): fact(n+1), ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept{
    if(k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

using P = pair<ll, ll>;

int main(void){
  ll n;
  cin >> n;
  ll zero = 0;
  map<P, P> mp;
  REP(i, n){
    ll a, b;
    cin >> a >> b;
    if(a == 0 && b == 0){
      zero++;
      continue;
    }
    ll g = gcd(a, b);
    a /= g;
    b /= g;
    if(b < 0){
      a = -a;
      b = -b;
    }
    bool rot = (a <= 0);
    if(rot){
      ll tmp = a;
      a = b;
      b = -tmp;
    }
    if(rot) mp[{a, b}].first++;
    else mp[{a, b}].second++;
  }
  mint ans = 1;
  for(auto p : mp){
    ll s = p.second.first;
    ll t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s)-1;
    now += mint(2).pow(t)-1;
    ans *= now;
  }
  ans -= 1;
  ans += zero;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 19132
#include <bits//stdc++.h>
using namespace std;
#define int long long
signed main(){
	string a[3];
	int b[3];
	cin>>a[0]>>a[1]>>a[2];
	b[0]=0,b[1]=0,b[2]=0;
	int t=0;
	while(1){
		if(b[t]==a[t].size()){
			cout<<(char)('A'+t)<<endl;
			return 0;
		}
		b[t]++;
		t=(int)(a[t][b[t]-1]-'a');
	}
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string a, b;
    cin >> a >> b;
    cout << b << a << endl;
    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (b <= 1) cout << 0 << endl;
	else if ((b+(a-1))/a <= 1) cout << 1 << endl;
	else cout << ((b-a)+(a-1-1))/(a-1) + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi c(n-1), s(n-1), f(n-1);
    rep(i, n-1) cin >> c[i] >> s[i] >> f[i];
    vi ans(n, 0);
    rep(i, n-1) {
        int t = 0;
        for (int j = i; j < n-1; ++j) {
            if (t < s[j]) {
                t = s[j] + c[j];
            } else {
                int m = t%f[j];
                if (m == 0) {
                    t += c[j];
                } else {
                    t += f[j] - m + c[j];
                }
            }
        }
        ans[i] = t;
    }
    rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n , m , x ; cin >> n >> m >> x ;
    vector<int>arr(m);
    for(int&p:arr) cin >> p ;
    // sort(arr.begin(),arr.end());
    int j = 0 , sum1 = 0 , sum2 = 0;
    for(int i = 0 ; i < m  ; i++)
    {
        if(arr[i]<x) 
        {
            sum1++; 
        }
        else 
        {
            sum2++;
        }
    }
    cout << min(sum1,sum2);
    return 0 ;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  int a,b;
  cin>>n;
  int ans=0;
  rep(i,n){
    cin>>a>>b;
    ans+=(b-a+1);
  }
  cout<<ans<<endl;
  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

//---------------------
struct UnionFind {
	vector<int> uf;
	vector<int> rk;
	int sz;

	UnionFind(int n) {
		sz = n;
		uf.resize(n);
		rk.resize(n);
		this->init();
	}

	void init() {
		rep(i,sz) {
			uf[i] = i;
			rk[i] = 0;
		}
	}

	int find(int a) {
		return uf[a] == a ? a : (uf[a] = this->find(uf[a]));
	}

	bool same(int a, int b) {
		return find(a) == find(b);
	}

	void merge(int a, int b) {
		int aa, bb;
		aa = find(a);
		bb = find(b);
		if(aa == bb) return;
		if(rk[aa] > rk[bb]) {
			uf[bb] = aa;
		}
		else {
			if(rk[aa] == rk[bb]) rk[bb]++;
			uf[aa] = bb;
		}
	}
};

//---------------------

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> p(N), rev_p(N);
	UnionFind uf(N);
	int res = 0;
	rep(i,N) {
		cin >> p[i];
		p[i]--;
		rev_p[p[i]] = i;
	}
	rep(i,M) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		uf.merge(x,y);
	}
	rrep(i,N) {
		if(uf.same(rev_p[i],i)) {
			res++;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int N;
	cin >> N;

	vector<int> vB(N-1, 0);
	rep(i, N-1) cin >> vB[i];

	vector<int> vA(N, 0);
	vA[0] = vB[0];
	for (int i = 1; i != N-1; ++i) {
		vA[i] = min(vB[i - 1], vB[i]);
	}
	vA[N - 1] = vB[N - 2];

	int cnt = 0;
	rep(i, N) cnt += vA[i];
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define MAX 1000000000000000000LL
ll inf=100000000000007;
using namespace std;

int main(){
    int n; cin>>n;
    int k;
    ll ans[200005]={};
    ll sum=0;
    for(int i=1; i<=n; i++){
        cin>>k;
        ans[i]=ans[i-1]+k;
        sum+=k;
    }
    ll mini=MAX;
    for(int i=1; i<n; i++){
        mini=min(mini,abs(sum-ans[i]*2));
    }
    cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
double PI = 3.141592653589793238;
vector<vector<int>>G(100030);
int main() {
	long long int n;
	cin >> n;
	for (int i = -200; i <= 200; i++) {
		for (int j = -200; j <= 200; j++) {
			long long int a = pow(i, 5);
			long long int b = pow(j, 5);
			if (a - b == n) {
				cout << i << " " << j;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 5432
function Main(input){
  var k = parseInt(input.split("\n")[0],10);
  var a = 0;
  var b = 0;
  for(i = 1; i <= k;i++){
    if(i % 2 == 0){
    	a++;
  	}else{
    	b++;
  	}
  }
  console.log(a * b);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <iostream>
#include<stdio.h>
#include <cstring>
#include <queue>
using namespace std;
const int NUM=100;
int dir[4][2]= {{-1,0},{0,+1},{+1,0},{0,-1}};
int ans,n,m,ma[NUM][NUM],startx,starty;
bool vis[NUM][NUM];
//int bfs(int x,int y);
void dfs(int x,int y,int step);
int main()
{
    //freopen("input.txt", "r", stdin);   //只改变输入流的文件指针，读入这个文件的内容（必须要有input这个文件）stdin是标准输入流的文件指针
    //freopen("output.txt", "w", stdout);
    while(~scanf("%d %d",&m,&n)&&n+m)
    {
        ans=0x3f3f3f3f;
        // memset(vis,0,sizeof vis);
        for (int i=0; i<n; i++)
        {
            for (int j=0; j<m; j++)
            {
                scanf("%d",&ma[i][j]);
                if (ma[i][j]==2)
                    startx=i,starty=j;
            }
        }
        //vis[startx][starty]=1;
        //ma[startx][starty]=0;
        dfs(startx,starty,0);
        //int ans=bfs(startx,starty);
        printf("%d\n",ans>10?-1:ans);
    }
    return 0;
}
/*int bfs(int x,int y)
{
    int ans=0;
    memset(vis,0,sizeof vis);
    vis[x][y]=1;
    queue<pair<int,int> > q;
    q.push(make_pair(x,y));
    while(!q.empty()&&!vis[endx][endy]&&ans<=10)
    {
        pair<int,int> p=q.front();
        q.pop();
        for(int i=0; i<4; i++)
        {
            int dx=x+dir[i][0];
            int dy=y+dir[i][1];
            if (dx>=0&&dx<n&&dy>=0&&dy<m&&!vis[dx][dy])
            {
                vis[dx][dy]=1;
                if (ma[dx][dy]==0)
                    q.push(make_pair(dx,dy));
                else if (ma[dx][dy]==1)
                {
                    ma[dx][dy]=0;
                    ans++;
                }
                else if (ma[dx][dy]==3)
                    break;
            }
        }
    }
    return ans>=10?-1:ans;
}*/
void dfs(int x,int y,int step)
{
    if (step>=10)
        return;
    step++;
    for (int i=0; i<4; i++)
    {
        int dx=dir[i][0]+x;
        int dy=dir[i][1]+y;
        if (dx>=0&&dx<n&&dy>=0&&dy<m&&ma[dx][dy]!=1)
        {
            while(ma[dx][dy]!=1&&ma[dx][dy]!=3&&dx>=0&&dx<n&&dy>=0&&dy<m)
            {
                dx+=dir[i][0];
                dy+=dir[i][1];
            }
            if (dx>=0&&dx<n&&dy>=0&&dy<m)
            {
                if (ma[dx][dy]==1)
                {
                    ma[dx][dy]=0;
                    dfs(dx-dir[i][0],dy-dir[i][1],step);
                    ma[dx][dy]=1;
                }
                else if (ma[dx][dy]==3)
                {
                    ans=min(ans,step);
                    return ;
                }
            }

        }
    }
    return ;
}



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

int k,a,b;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>k>>a>>b;
    if((a+k-1)/k*k<=b)cout<<"OK\n";
    else cout<<"NG\n";

    return 0;
}

Measured memory_bytes: 3652
s = int(input())
X = set()
X.add(s)


def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


for ans in range(2, 10 ** 6 + 1):
    am = f(s)
    if am in X:
        print(ans)
        break
    else:
        s = am
        X.add(am)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
	int x, y;
	cin >> x >> y;
	if (y % 2 == 0 && y >= 2 * x && y <= 4 * x)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3500
N, K = map(int,input().split())
a = []
n = 1

while n <= N:
     a = a + [n]
     n += 1
for i in range(K):
     d = int(input())
     A = list(map(int,input().split()))
     for j in range(d):
          if A[j] in a:
               a.remove(A[j])
ans = len(a)
print(ans)

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

int main()
{
    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    if (A >= K) {
        cout << K << endl;
    } else if (A + B >= K) {
        cout << A << endl;
    } else {
        cout << A - (K - (A + B)) << endl;
    }
    return 0;
}

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

int main(void){
  	int a, b;
	cin >> a >> b;
  	cout << a * b;
	return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
using namespace std;
int a[200100],p[200100];
bool pd(int x1,int x2,int x3){
	int y,z;
	if(x1<x2&&x1<x3) y=x2,z=x3;
	else if(x2<x1&&x2<x3) y=x3,z=x1;
	else if(x3<x1&&x3<x2) y=x1,z=x2;
	if(y<z) return 0;
	return 1;
}
int main(){
//	freopen("F.in","r",stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		p[a[i]]=i;
	}
	int T=0,f;
	for(int i=n-1;i>=1;i--)
	{
		if(T==0){
			if(p[i]<p[i+1])
				continue;
			T=1;
			f=i+1;
		}
		else{
			if(pd(p[f],p[i],p[i+1]))
				T++,f=i+1;
		}
	}
	printf("%d\n",T);
	return 0;
}


Measured memory_bytes: 1664
import sys
input=sys.stdin.readline

import math
import itertools

N = int(input())
XY=[list(map(int,input().split())) for i in range(N)]

if (N>2):
  ali =[]
  for i in itertools.permutations(XY,N):
    for j in range(N-1):
      ali.append(math.sqrt(((i[j][0] - i[j+1][0])**2)+((i[j][1] - i[j+1][1])**2)))
  print(sum(ali)/math.factorial(N))
else:
  ali = []
  for i in itertools.permutations(XY,2):
    ali.append(math.sqrt(((i[0][0] - i[1][0])**2)+((i[0][1] - i[1][1])**2)))
  print(sum(ali)/math.factorial(N))
    



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

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

typedef long long ll;

ll INF = 100000000000000;
ll MOD = 1e9+7;

int main(){
   ll N,K;string S;
   cin >> N >> K >> S;
   ll cnt = 0;
   for(int i = 0;i < N-1;i++){
       if(S[i] == S[i+1]){
           cnt++;
       }
   }
   cout << min(cnt + K * 2,N-1) << endl;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;
typedef pair<int,int> ii;

ll A,B,N;

void solve() {

}

ll calc(ll x) {
  assert( A * x >= 0LL );
  assert( A * (ll)(x/B) >= 0LL );
  return (ll)(A*x/B) - A * (ll)(x/B);
}

ll bf() {
  ll maxi = 0;
  rep(x,N+1){
    maxi = max(maxi,calc(x));
  }
  return maxi;
}

ll prop() {
  ll ret = 0;
  rep(_,30) {
    ll v = rand() % N + 1;
    REP(d,-20,21) {
      ll w = v + d;
      if( !( 0 <= w && w <= N) ) continue;
      ret = max(ret, calc(w));
    }
  }
  return ret;
}

int main() {
  srand((unsigned int)time(NULL));
  cin >> A >> B >> N;
  /*
  int t = 10000000;
  REP(a,999950,t) {
    REP(b,5000000,t) {
      REP(c,1000000,t) {
  A = a;
  B = b;
    N = c;
  */
  ll maxi = -LLONG_MAX;
  //for(ll x=N;x>=0;--x) {
  /*
  for(ll x = 0 ; x <= N; ++x) {
    cout << "* " << x << " : " << calc(x) << endl;
  }
  */
  ll top = min(5000001LL,N);
  //ll top = min(A,N);
  rep(x,top+1) {
    //cout << "* " << x << " : " << calc(x) << endl;
    ll v = calc(x);
    maxi = max(maxi,v);
  }
  rep(x,top+1) {
    ll y = N - (ll)x;
    if( y < 0 ) break;
    maxi = max(maxi,calc(y));
  }
  maxi = max(maxi,calc(min(B-1,N)));
  ll med = N / 2;
  ll ts = 1000010;
  REP(d,-ts,ts+1) {
    ll vs = med + ts;
    if( 0 <= vs && vs <= N ) {
      maxi = max(maxi,calc(vs));
    }
  }
  
  ll r = prop();
  maxi = max(r,maxi);
  //cout << "r = " << r << endl;
  cout << maxi << endl;
  //assert( maxi >= r );
    
  //ll bfa = bf();
  //cout << "Ans: " << bfa << endl;
  /*
  if( maxi != bfa ) {
    cout << "FAILED... " << A << " " << B << " " << N << endl;
  }
  assert( maxi == bfa);
  }
    }
  }
  */
  return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#define abs(a) (a>0) ? (a) : (-(a))

int main()
{
    int n,x,i,sa,karisa,karisamin,city[100010],flag=1;
	scanf("%d %d",&n,&x);
	city[0]=x;
	if(x!=1)sa=x-1;
	sa=1000000000;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&(city[i]));
		karisa=abs((city[i]-city[i-1]));
		if(sa>karisa)sa=karisa;
	}
	karisamin=sa;
	while(flag)
	{
		flag=0;
		for(i=1;i<=n;i++)
		{
			karisa=abs(((city[i]%sa)-(city[i-1]%sa)));
			if(karisa!=0)
			{
				flag=1;
				if(karisamin>karisa)karisamin=karisa;
			}
		}
		if(flag==1)sa=karisamin;
		if(sa==1)flag=0;
	}
	
    printf("%d",sa);
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            HashSet<Integer> a = new HashSet<Integer>();

            for (int i = 0; i < n; i++) {
                a.add(in.nextInt());
            }


            out.print(a.size());
        }

    }
}



Measured memory_bytes: 21844
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


def find_shortest_cycle(G, s):
    dq = deque()
    N = len(G)
    INF = float('inf')
    dist = [INF] * N
    dist[s] = 0
    parent = [-1] * N

    ans_last = None # sからループを探して見つかった時の、ループの最後の頂点番号
    dq.append(s)
    # BFSで、最短のループを見つける
    while dq and ans_last is None:
        v = dq.popleft()
        d = dist[v]
        for n in G[v]:
            # 頂点vからいける頂点の中に開始点があったら、ループである
            if dist[n] == 0:
                ans_last = v
                parent[n] = v
                break
            # まだ探索していない頂点なら次の探索候補にする
            elif dist[n] == INF:
                dist[n] = d + 1
                parent[n] = v
                dq.append(n)

    # ループが見つかった場合
    if ans_last:
        # ループの最後の頂点から、元の頂点をたどり、そのルートを逆にする
        g = ans_last
        route = [g]
        while g != s:
            g = parent[g]
            route.append(g)
        return list(reversed(route))
    
    # 見つからなかった場合はNoneを返す
    return None

def main():
    N, M, *A = map(int, read().split())

    G = [[] for i in range(N+1)]
    for a, b in zip(A[::2], A[1::2]):
        G[a].append(b)

    # すべての頂点の入次数が 1、出次数が 1 であるような G の誘導部分グラフ
    # [すべての頂点の入次数が 1、出次数が 1 のグラフ] -> ループ

    # 有向グラフ G=(V,E) に対し、次のような条件を満たす有向グラフ G′=(V′,E′) を G の誘導部分グラフと呼ぶ。
    # V′ は V の (空でない) 部分集合である。
    # E′ は、E の辺であって両端点がともに V′ に含まれるものすべてを含む集合である。

    # -> ループでも、ショートカットできるようなループはだめ

    # 例: 1 -> 2 -> 3 -> 4 -> 5
    #     ^    |         ^    |
    #     |    ----------|    |
    #     ---------------------
    # V' = {1, 2, 3, 4, 5} としてしまうと、
    # E' = {(1->2), (2->3), (3->4), (2->4), (4->5), (5->1)}
    # となってしまい、この誘導部分グラフG'=(V', E')において、
    # 頂点2の出次数が2になってしまう。（頂点4の入次数も2になってしまう）
    # V' = {1, 2, 4, 5} とすれば、
    # E' = {(1->2), (2->4), (4->5), (5->1)}
    # となり、すべての頂点の入次数が 1、出次数が 1 となる
    
    # つまり、ショートカットできない最短のループを1つでも見つければよい
    
    min_route = None
    for s in range(1, N+1):
        # 各頂点を開始点にしてループを探す
        route = find_shortest_cycle(G, s)
        # ループが複数ある場合、短いほうを採用
        if route:
            if min_route is None or len(route) < len(min_route):
                min_route = route
    
    if min_route:
        print(len(min_route), *min_route, sep='\n')
    else:
        print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3692
#include<stdio.h>

int main(void){
    // n: 入力
    // i: ケーキの個数
    // j: ドーナツの個数
    // flag: Y/Nの判定フラッグ
    int n, i, j, flag = 0;
    scanf("%d", &n); // AtCoderはC99でscanf_sは無い

    // iの最大値はjが0の時
    // n = 4 * i + 7 * 0
    // よって, i = n / 4 のとき
    // 同様にjの最大値はj = n / 7
    for(i = 0; i <= n / 4; i++){
        for(j = 0; j <= n / 7; j++){
            if(4 * i + 7 * j == n){
                flag = 1;
            }
        }
    }

    if(flag){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128