akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,m,d;
    cin >> n >> m >> d;
    long double ans;
    if(d==0){
        ans=(m-1);
        ans/=n;
    }
    else{
        ans=2*(m-1)*(n-d);
        ans/=(n*n);
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

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

using namespace std;

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

const uint64_t mod = 1000000007;

uint64_t po(uint64_t d, uint64_t n){
  if(n == 1) return d;
  if(n == 0) return 1;
  uint64_t p = po(d, n >> 1);
  p = p * p % mod;
  if(n & 1) p = p * d % mod;
  return p;
}

int main(){
  uint64_t r = 0;
  int n, k;
  cin >> n >> k;
  vector<int> a(k + 1);
  for(int m = k + 1; --m; ){
    uint64_t p = po(k / m, n);
    for(int v = 2; m * v <= k; ++v){
      p = (p + mod - a[m * v]) % mod;
    }
    a[m] = p;
    r = (r + p * m) % mod;
  }
  cout << r << endl;
  return 0;
}

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

const int N = 333;

int f[N][N][N], n, K, MOD;

int main(void) {
  scanf("%d%d%d", &n, &K, &MOD);
  f[0][1][0] = 1;
  for(int i = 0; i <= n; i++) {
    for(int j = 1; j <= K; j++) {
      for(int k = i; ~k; k--) {
	if(k) {
	  (f[i][j][k - 1] += f[i][j][k]) %= MOD;
	} else {
	  (f[i][j + 1][i] += f[i][j][k]) %= MOD;
	}
	(f[i + 1][j][k] += 1LL * (k + 1) * f[i][j][k] % MOD) %= MOD;
      }
    }
  }
  cout << f[n][K + 1][n] << endl;
}


Measured memory_bytes: 131200
s = input()

w = "keyence"
ans = "NO"

# keyencexxxxx
if s[:7] == w:
    ans = "YES"

# xxxxkeyence
if s[-7:] == w:
    ans = "YES"

# key xxx ence
for i in range(1, 7):
    ss = w[:i]
    tt = w[-7+i:]
    if s[: len(ss)] == ss and s[-len(tt):] == tt:
        ans = "YES"
        break

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n + 1,0);
  vector<ll> b(n,0);
  REP(i, n + 1){cin >>a[i];}
  REP(i, n){cin >>b[i];}

  ll ans = 0;
  REP(i, n){
    ll tmp =  min(a[i],b[i]);
    ans += tmp;
    b[i] -= tmp;
    a[i] -= tmp;
    tmp = min(a[i + 1],b[i]);
    a[i + 1] -= tmp;
    b[i] -= tmp;
    ans += tmp;
  }
  // REP(i, n + 1){
  //   cout << a[i] << endl;
  // }
  // cout << "b" << endl;
  // REP(i, n){
  //   cout << b[i] << endl;
  // }
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
static vector<uint64_t> cities;

int32_t main()
{
  uint64_t N, A, B;
  cin >> N >> A >> B;

  for (uint64_t i = 0; i < N; i++) {
    uint64_t X;
    cin >> X;
    cities.push_back(X);
  }

  uint64_t dist = 0;
  for (uint64_t i = 0; i < cities.size() - 1; i++) {
    uint64_t walk = (cities[i + 1] - cities[i]) * A;
    if (B < walk) {
      dist += B;
    } else {
      dist += walk;
    }
  }

  cout << dist << endl;

  return 0;
}


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

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

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int ans = 0;
    rep(i, 1000){
        int k = 0;
        rep(j, n){
            int num[3] = {i / 100, i / 10 % 10, i % 10};
            if(s[j]-'0' == num[k]){
                k++;
            }

            if(k == 3) {
                break;
            }            
        }
        if(k == 3){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

int f(int x){
  string s = to_string(x);
  int c = 0;
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j <= 9; j++){
      if(s[i] == j + 48){c += j; break;}
    }
  }
  return c;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  long long sum = 0;
  for(int i = 0; i <= n; i++){
    if(f(i) >= a && f(i) <= b){
      sum += i;
    }
  }
  cout << sum << endl;
}

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

int main(){
		int N;
		cin >> N;
		int count;
		if(N>=195)count=5;
		else if(N>=189)count=4;
		else if(N>=165)count=3;
		else if(N>=135)count=2;
		else if(N>=105)count=1;
		else count=0;
		cout << count << endl;
}


Measured memory_bytes: 384
#include <iostream>

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

	int n;
	for (n = 0;; n++){
		if (((A - 1) * (n - 1) + A) >= B)
			break;
	}

	std::cout << n << std::endl;

	return 0;
}


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

int N, M;
vector<int>as;
vector<int>bs;
vector<int> getans(const int l, const int r,const int depth) {
	auto lit = upper_bound(as.begin(), as.end(),l);
	auto rit = lower_bound(as.begin(), as.end(), r);
	if (lit == rit) {
		int rank = bs[prev(lit) - as.begin()];
		vector<int>nums(N+1);
		int rest = (r - l) / 2;
		int ok = 0;
		for (int i = N; i >=0; --i) {
			nums[i] = rest;
			if (i == rank)ok = rest;
			rest /= 2;
		}
		vector<int>anss(N + 1);
		for (int i = 0; i <= depth; ++i) {
			anss[i] = ok+((i==rank)?1:0);
		}
		return anss;
	}
	else {
		auto lans(getans(l, (l + r) / 2, depth + 1));
		auto rans(getans((l + r) / 2, r, depth + 1));
		vector<int>anss(N + 1);
		for (int i = 0; i <=depth; ++i) {
			anss[i] = max(anss[i], lans[i] + rans[depth+1]);
		}
		for (int i = 0; i <=depth; ++i) {
			anss[i] = max(anss[i], rans[i] + lans[depth+1]);
		}
		return anss;
	}
}
int main() {cin >> N >> M;
	as.resize(M + 1);
	bs.resize(M);
	for (int i = 0; i <= M; ++i) {
		cin >> as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> bs[i];
	}
	auto v= getans(0, (1 << N),0);
	cout << (1<<N)-v[0] << endl;
	return 0;
}

Measured memory_bytes: 3156
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
#include<random>
using namespace std;
#define int long long
//#define double long double
//typedef unsigned long long ulong;
typedef pair<int, int> pii;
typedef pair<int, pii > piii;
typedef pair<double, double> pdd;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 61ll)
#define mod 1000000007

int N;
int sum;
int wa;
int a[200200];

int abss(int A){
    if(A < 0)return -A;
    return A;
}


signed main(){
    cin >> N;
    int ans = INFL - 1;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        wa += a[i];
    }
    for(int i = 0; i < N; i++){
        sum += a[i];
        ans = min(ans, abss(wa - sum - sum));
    }
    cout << ans << endl;

    
    

    return 0;
}

/*

*/

Measured memory_bytes: 1792
#include <iostream>
#define endl '\n'
using namespace std;
int main()
{   int t;
    cin>>t;
    if(t<=599 && t>=400){
        cout<<"8";
    }
    else if(t<=799 && t>=600){
        cout<<"7";
    }
  else   if(t<=999 && t>=800){
        cout<<"6";
    }
    
   else  if(t<=1199 && t>=1000){
        cout<<"5";
    }
   else  if(t<=1399 && t>=1200){
        cout<<"4";
    }
  else  if(t<=1599 && t>=1400){
        cout<<"3";
    }
    else  if(t<=1799 && t>=1600){
        cout<<"2";
    }
    else  if(t<=1999 && t>=1800){
        cout<<"1";
    }
}


Measured memory_bytes: 3588
N = int(input())
cards = {}
for _ in range(N):
    fraise = input()
    if not fraise in cards:
        cards[fraise] = 1
    else:
        cards[fraise] += 1
M = int(input())
for _ in range(M):
    fraise = input()
    if not fraise in cards:
        cards[fraise] = -1
    else:
        cards[fraise] -= 1
max = 0
for card in cards:
    if cards[card] > max:
        max = cards[card]
print(max)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

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

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-10;
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003


int dp[353][353]={0};
int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,s,g,d;
P ps[101];
bool c[200][200];
bool amida(){
	
	int k=s-1;
	rep(i,d){
		if(c[i][k-1]){
			//cout<<"l"<<endl;
			k--;
		}
		else if(c[i][k]){
			//cout<<"r"<<endl;
			k++;
	}
	} 
	if(k==g-1)
		return true;
	else
		return false;
	
}
int main(){
	
	while(cin>>n,n!=0){
		cin>>s>>g>>d;
		rep(i,d){
				string r;
			cin>>r;
			for(int j=0;j<n-1;j++){
				c[i][j]=r[j] == '1';
				c[i][j+1]=false;
			}
		}
		if(amida()){
			cout<<0<<endl;
			continue;
	}
			bool f=false;
			rep(i,d){
				rep(j,n-1){
					if((j==0||!c[i][j-1])&&!c[i][j]&&!c[i][j+1]){
						c[i][j]=true;
						if(amida()){
							cout<<i+1<<" "<<j+1<<endl;
							f=true;
							break;
						}
						
						c[i][j]=false;
					}
				}
				if(f)
					break;
			}
			if(!f)	
				cout<<1<<endl;
		}
		
	
	
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main () {
    int n;
    cin >> n;
    vector<int> vs(n, 0);
    for (int i = 0; i < n; i++) { cin >> vs[i];}
    sort(vs.begin(), vs.end());

    long double ans = 0.0;
    ans = (long double)vs[0];
    for (int i = 1; i < n; i++) {
        ans = (ans + (long double)vs[i]) / 2.0;
    }
    printf("%.10Lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<int> a(n+1), cnt(n+1, 0); //i番目のボールの個数
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<int> b;
  for (int i = n; i >= 1; --i) {
    int sum = 0; //iの倍数の箱に入っているボールの個数
    for (int j = 2; i * j <= n; ++j) {
      sum += cnt[i*j];
    }
    if ((a[i] + sum) % 2 == 1) {
      b.emplace_back(i); //i番目の箱にボールを入れる
      cnt[i]++;
    }
  }
  int m = b.size();
  cout << m << "\n";
  rep(i,m) {
    cout << b[i] << " ";
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int N, W;
	cin >> N >> W;
	
	vector<int> v(N);
	vector<int> w(N);
	int maxVal = 0;
	for(int i = 0; i < N; i++)
	{
			cin >> w[i] >> v[i];
			maxVal += v[i];
	}
		
	int maxSoFar = 0;
	
	vector<vector<ll>> dp(maxVal + 1, vector<ll>(N + 1, LLONG_MAX));
	
	for(int i = 0; i <= maxVal; i++)
	{	
		for(int j = 0; j <= N; j++)
		{
			if(i == 0 ) dp[i][j] = 0;
			else if(j == 0) dp[i][j] = LLONG_MAX;
			else
			{
				ll x = LLONG_MAX, y = LLONG_MAX;
				if((i - v[j - 1]) >= 0)
				{
					x = (dp[i - v[j - 1]][j - 1] == LLONG_MAX) ? LLONG_MAX : dp[i - v[j - 1]][j - 1] + w[j - 1];
				}
				y = dp[i][j - 1];
				
				dp[i][j] = min(x, y);
				
				if(dp[i][j] <= W) maxSoFar = i;
			}
		}
		
	}
	
	cout << maxSoFar << endl;
}


Measured memory_bytes: 85180
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n % 2)ans = ans * x % MOD;
    return ans;
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
ll combi(ll n,ll r){
    ll num = 1;
    for(ll i = 1;i <= r;i++){
        num = divmod((n-i+1)*num,i);
    }
    return num;
}

main(){
    int X,Y;
    cin >> X >> Y;
    
    if((X + Y) % 3){
        cout << 0 << endl;
        return 0;
    }
    int N = (X + Y) / 3;
    if(X - N < 0 || Y - N < 0){
        cout << 0 << endl;
        return 0;
    }
    ll x2 = X - N, y2 = Y - N;
    ll ans = combi(x2 + y2, x2);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = 2e18 + 5;
  if (n % k == 0)
    cout << 0;
  else
  cout << min(abs(n % k - k), n);

  return 0;
}


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

const int N = 330;

int k, dp[N][N][N];
string s;

void _max(int &a, int b) {
	a = max(a, b);
}

void solve() {
	for (int i = 0; i < s.length(); i++)
		for (int j = 0; j < N; j++)
			dp[i][i + 1][j] = 1;
	
	for (int len = 2; len <= s.length(); len++)
		for (int l = 0; l + len <= s.length(); l++) {
			int r = l + len;
			for (int cnt = 0; cnt <= k; cnt++) {
				dp[l][r][cnt] = max(dp[l + 1][r][cnt], dp[l][r - 1][cnt]);
				if (s[l] == s[r - 1])
					_max(dp[l][r][cnt], 2 + dp[l + 1][r - 1][cnt]);
				else if (cnt)
					_max(dp[l][r][cnt], 2 + dp[l + 1][r - 1][cnt - 1]);
			}
		}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s >> k;
	solve();
	cout << dp[0][s.length()][k];
}

Measured memory_bytes: 129152
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 ll n,k;
 ll dp[110][100010];// (i,x)n of ways to have distribute x candies for the first i kids
 ll dp2[110][100010];// prefix sum of dp  dp2[i][x] sum of dp [i][0,1,2,...x]
 ll a[109];
 
 const ll mod=1e9+7;
 
 ll sum(int i,int left,int right){
     if(left!=0){
     return dp2[i][right]-dp2[i][left-1];}
      return dp2[i][right];
 }
 
  
int main()
{
    cin>>n>>k;
   
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
   
 
//cout<<sum(1,0,1);return 0;
     for(ll i =1;i<=n;i++){
       for(ll j=0;j<=k;j++){
           //j=total of candies distributed
           // if i want to have 10 in total and ai = 5 then i need at least 5 so i nueed sum from 5 upto 10
           
           if(i==1){
              if(j<=a[i]){
               dp[i][j]=1ll;}
           }else if(j-a[i]<=0){
              dp[i][j] = dp2[i-1][j] % mod;
           }else{
                dp[i][j]=(dp2[i-1][j]-dp2[i-1][j-a[i]-1]+mod)%mod;
           }if(j==0){
               dp2[i][j]=1;
           }else{
               dp2[i][j]=(dp2[i][j-1]+dp[i][j])%mod;
           }
          // cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
           
       }
           
       }
        //cout<<ans;
   cout<<dp[n][k]%mod;
}

Measured memory_bytes: 159784
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define time fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<30
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

int cnt[3][31];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, c;
    cin >> n >> c;
    int d[c+1][c+1];
    for(int i=1; i<=c; i++)
        for(int j=1; j<=c; j++)
            cin >> d[i][j];
    int col[n+1][n+1];
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            cin >> col[i][j];
            cnt[(i+j)%3][col[i][j]]++;
    
        }
    }
    
    int ans = inf, tmp = 0;
    for(int i=1; i<=c; i++){
        for(int j=1; j<=c; j++){
            if(i==j) continue;
            for(int k=1; k<=c; k++){
                if(j==k || i==k) continue;
                int tmp = 0;
                for(int z=1; z<=c; z++){
                    tmp += (d[z][i]*cnt[0][z] + d[z][j]*cnt[1][z] + d[z][k]*cnt[2][z]);
                            }
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            auto itr = lower_bound(l.begin() + j, l.end(), l[i] + l[j]);
            ans += distance(l.begin() + j,itr - 1);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int R,G;cin >> R >> G;
  cout << 2*G - R << endl;
  return 0;
}


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

using namespace std;
#define int unsigned long long
const int mod = 1e9+7;
int qpow(int a,int b){
	int s=1;
	while(b){
		if(b%2) s=(s*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return s%mod;
}
signed main(){
	int n;
	cin>>n;
	int ans=0;
	ans=((qpow(10,n)+qpow(8,n))%mod-(qpow(9,n)*2)%mod+mod)%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
#define ran 222222
int n;
vector<int> e[ran];
int deg[ran];
int q[ran],lq;

vector<int> bad[ran];
int col[ran];

vector<int> _bad[ran];
int _col[ran];

void save(){
	for(int i=1; i<=n; i++){
		_bad[i] = bad[i];
		_col[i] = col[i];
	}
}
void rollback(){
	for(int i=1; i<=n; i++){
		bad[i] = _bad[i];
		col[i] = _col[i];
	}
}
bool chk(int x,int val,int cond){
	int y = x;
	while(true){
		int z;
		for(vector<int>::iterator it = e[y].begin(); it!=e[y].end(); it++){
			z = *it;
			if(col[z] == -1)break;
		}
		if(z == x){
			if(cond == -1)return col[y] != val;
			return col[y] == cond;
		}else{
			bad[z].push_back(y==x?val:col[y]);
			sort(bad[z].begin(),bad[z].end());
			bad[z].resize(unique(bad[z].begin(),bad[z].end())-bad[z].begin());
			for(col[z] = 0; col[z] < bad[z].size() && bad[z][col[z]] == col[z]; col[z]++);
			y = z;
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		int x;
		scanf("%d",&x);
		e[i].push_back(x);
		deg[x] ++;
	}
	for(int i=1; i<=n; i++){
		if(deg[i] == 0){
			q[lq++] = i;
		}
	}
	memset(col,-1,sizeof(col));
	for(int i=0; i<lq; i++){
		int x = q[i];
		sort(bad[x].begin(),bad[x].end());
		bad[x].resize(unique(bad[x].begin(),bad[x].end())-bad[x].begin());
		for(col[x] = 0; col[x] < bad[x].size() && bad[x][col[x]] == col[x]; col[x]++);

		for(vector<int>::iterator it = e[x].begin(); it!=e[x].end(); it++){
			int y = *it;
			bad[y].push_back(col[x]);
			if(--deg[y] == 0){
				q[lq++] = y;
			}
		}
	}
	for(int i=1; i<=n; i++)if(col[i] == -1){
		int x = i;
		sort(bad[x].begin(),bad[x].end());
		bad[x].resize(unique(bad[x].begin(),bad[x].end())-bad[x].begin());

		int Z;
		for(Z = 0; Z < bad[x].size() && bad[x][Z] == Z; Z++);

		save();

		if(chk(x,Z,-1)){
			puts("POSSIBLE");
			return 0;
		}

		rollback();

		int Z1=Z;
		for(Z ++; Z-1 < bad[x].size() && bad[x][Z-1] == Z; Z++);
		if(chk(x,Z,Z1)){
			puts("POSSIBLE");
			return 0;
		}

		puts("IMPOSSIBLE");
		return 0;
	}
	puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 31488
//ChooseIntegers.cpp (B)
#include <iostream>
#include <string>
using namespace std;

int main(){
  int A,B,C;
  bool flag = false;
  cin >> A >> B >> C;
  for(int i = 1; i < B; i++){
    if(A*i%B==C) flag = true;
  }
  if(flag) printf("YES\n");
  else printf("NO\n");
}


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

int gcd(ll a, ll b){
    if(a % b == 0) return b;
    else return gcd(b, a%b);
}

int many_gcd(vector<ll> v){
    int G = v[0];
    rep(i, v.size()){
        G = gcd(G, v[i]);
    }
    
    return G;
}

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

    int s[2], g[2];
    cin >> s[0] >> s[1] >> g[0] >> g[1];
    
    rep(i, g[1] - s[1]) cout << 'U';
    rep(i, g[0] - s[0]) cout << 'R';
    
    rep(i, g[1] - s[1]) cout << 'D';
    rep(i, g[0] - s[0]) cout << 'L';
    
    cout << 'L';
    rep(i, g[1] - s[1] + 1) cout << 'U';
    rep(i, g[0] - s[0] + 1) cout << 'R';
    cout << 'D';
    
    cout << 'R';
    rep(i, g[1] - s[1] + 1) cout << 'D';
    rep(i, g[0] - s[0] + 1) cout << 'L';
    cout << 'U' << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
#define ll long long int
#define endl '\n'
#define mp make_pair
#define pb push_back
#define mod 1000000007

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	char c;cin>>c;
	char d = (char)c+1;
	cout<<d<<endl;
return 0;
}



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

vector<int> G;

long cont;

void insertSort(int a[],int n,int g){
    int i,j,v;
    for (i = g; i < n; ++i) {
        v=a[i];
        j=i-g;
        while (j>=0&&a[j]>v){
            a[j+g]=a[j];
            j-=g;
            cont++;
        }
        a[j+g]=v;
    }
}

void shellSort(int a[],int n){
    //????????°???G={1,4,13,40??????}
    int h=1;
    int i;
    while (1){
        if (h>n)
            break;
        G.push_back(h);
        h=3*h+1;
    }

    for (i = G.size()-1; i >=0; --i) {
        insertSort(a,n,G[i]);
    }
}

int main() {
    int n,i,a[1000001];
    cont=0;
    cin>>n;
    for (i = 0; i < n; ++i) {
        cin>>a[i];
    }
    shellSort(a,n);

    cout<<G.size()<<endl;

    for (i = G.size()-1; i >=0 ; --i) {
        cout<<G[i];
        if (i)
            cout<<" ";
    }

    cout<<endl;
    cout<<cont<<endl;

    for (i = 0; i < n; ++i) {
        cout<<a[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 7016
#include <iostream>

using namespace std;

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

    int N;
    cin >> N;

    long long A[N + 2];
    A[0] = A[N + 1] = 0LL;
    long long current = 0LL, cost = 0LL;
    for (int i = 1; i <= N + 1; ++i) {
        if(i <= N) {
            cin >> A[i];
        }

        cost += abs(A[i] - current);
        current = A[i];
    }

    for (int i = 1; i <= N; ++i) {
        cout << cost - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]) << endl;
    }
}

Measured memory_bytes: 2048
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
if A[0] != 0:
  print(0)
  exit()
AC = list(Counter(A).items())
AC.sort()
MOD = 998244353
ans = 1
last_v = 1
last_k = -1
for k, v in AC:
  if k == 0:
    if v != 1:
      print(0)
      exit()
    last_k = 0
    continue
  if k != last_k+1:
    print(0)
    exit()
  ans = ans*pow(last_v, v, MOD)%MOD
  last_v = v
  last_k = k
print(ans)

Measured memory_bytes: 92696
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> vl;
typedef vector<vector<long long> > vll;
typedef vector<P> vp;
typedef vector<vector<P> > vpp;
struct Edge {
	int from;
	int to;
	ll cost;
};
// make the adjacent list from the edge list
vector<vector<P> > makeAdj(int k, int n, const vector<Edge>& e) {
	// n:the number of vertex
	// k=0:undirected, k=1:directed
	vector<vector<P> > ret(n, vector<P>(0));
	for(int i=0; i<e.size(); ++i) {
		ret[e[i].from].push_back(P(e[i].to, e[i].cost));
		if(k==0) ret[e[i].to].push_back(P(e[i].from, e[i].cost));
	}
	return ret;
}
// Do dijkstra
vector<ll> dijkstra(int s, const vector<vector<P> >& adj) {
	int n=(int)adj.size();
	vector<ll> dis(n, INF*INF);
	priority_queue<P, vector<P>, greater<P> > q;
	dis[s]=0;
	q.push(P(0, s));
	while(!q.empty()) {
		P buf=q.top();
		q.pop();
		ll d=buf.first;
		ll p=buf.second;
		if(dis[p]<d) continue;
		for(int i=0; i<adj[p].size(); ++i) {
			ll nd=adj[p][i].second;
			ll np=adj[p][i].first;
			if(dis[np]>dis[p]+nd) {
				dis[np]=dis[p]+nd;
				q.push(P(dis[np], np));
			}
		}
	}
	return dis;
}int main() {
	ios::sync_with_stdio(false);
	int N;
	cin>>N;
	vector<Edge> e(N-1);
	REP(i,N-1) {
		int a,b,c;
		cin>>a>>b>>c;
		--a;
		--b;
		e[i].from=a;
		e[i].to=b;
		e[i].cost=c;
	}
	vector<vector<P> > adj=makeAdj(0,N,e);
	int q,k;
	cin>>q>>k;
	--k;
	vector<ll> dis=dijkstra(k,adj);
	REP(i,q) {
		int x,y;
		cin>>x>>y;
		--x;
		--y;
		cout<<dis[x]+dis[y]<<endl;
	}
}



Measured memory_bytes: 12656
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	while(n >= 4){
		if(n == 0 || n % 4 == 0 || n % 7 == 0) return cout << "Yes\n",0;
		n -= 7;
	}
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;
int main(int argc, const char * argv[]) {

    int D;
    long long G;
    cin >> D >> G;
    vector<long long> p(D);
    vector<long long> c(D);
    
    for(int i = 0; i < D; i++){
        cin >> p[i] >> c[i];
    }
    
    int ans = INT_MAX;
    
    for(int tem = 0; tem < (1 << D); tem++){
        bitset<10> bit(tem);
        long long sum = 0;
        int count = 0;
        for(int i = 0; i < D; i++){
            if(bit.test(i)){
                sum += p[i] * ((i + 1) * 100)   + c[i];
                count += p[i];
            }
        }
        
        for(int i = D - 1; i >= 0; i--){
            // 判定：解答してない問題の判定
            if(!bit.test(i)){
                for(int j = 0; j < p[i]; j++){
                    if(sum < G){
                        sum += (i + 1) * 100;
                        count++;
                    }
                    else break;
                }
            }
        }
        ans = min(ans, count);
        
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [int(input()) for _ in range(N)]
first = max(a)
f_id = a.index(max(a))
second = max(a[:f_id] + a[f_id+1:])

for i in range(N):
  if a[i] == first:
    print(second)
  else:
    print(first)
  

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

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

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

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

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

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

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

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

fn factorial(n: u32) -> u32 {
    let mut ans = 1;
    for i in 2..(n + 1) {
        ans *= i;
    }
    ans
}

fn permutation(n: u32, r: u32) -> u32 {
    let mut p = 1;
    for i in 0..r {
        p *= n - i;
    }
    p
}

fn combination(n: u32, r: u32) -> u32 {
    permutation(n, r) / factorial(r)
}

fn exe(a: u32, b: u32) -> u32 {
    let mut o = 0;
    let mut s = 0;
    if a >= 2 {
        o = combination(a, 2);
    }
    if b >= 2 {
        s = combination(b, 2);
    }
    o + s
}

fn main() {
    input! {
        a: u32,
        b: u32,
    }
    let ans = exe(a, b);
    println!("{}", ans);
}

#[test]
fn test() {
    assert_eq!(exe(4, 3), 9);
    assert_eq!(exe(1, 1), 0);
    assert_eq!(exe(13, 3), 81);
    assert_eq!(exe(0, 3), 3);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = 998244353;

int N;
vi A, B, C;
int rui[100010];

signed main()
{
	cin >> N;
	A.resize(N), B.resize(N), C.resize(N);

	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N) cin >> C[i];

	sort(all(A));
	sort(all(B));
	sort(all(C));

	for (int i = 0; i < N; ++i) {
		int a = N - (upper_bound(all(C), B[i]) - begin(C));

		rui[i] = a;
	}

	for (int i = N - 1; i >= 0; --i) {
		rui[i] += rui[i + 1];
	}

	int ans = 0;

	rep(i, N) {
		int pos = upper_bound(all(B), A[i]) - begin(B);

		ans += rui[pos];
	}

	cout << ans << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, A, B;
	cin >> N >> A >> B;
	ll a=0, b=0, c=0;
	REP(i, N){
		ll P;
		cin >> P;
		if(P<=A) a++;
		if(P>=A+1 && P<=B) b++;
		if(P>=B+1) c++;
	}
	cout << min(a, min(b, c)) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 1<<21;

int n;
int p[MAXN];

int main()
{
	
	cin >> n;
	for (int i = 1; i <= n; ++ i)
		cin >> p[i];
	sort(p+1, p+n+1);
	int a = p[n/2];
	int b = p[n/2+1];
	cout << b-a << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int node[5];

int main(){
    Int K, A, B; cin >> K >> A >> B;
    Int ans = 1;
    if (K >= (A-1)){
        ans = A;
        K -= (A-1);
    }
    if (B-A >= 2){
        ans += (B-A)*(K/2);
        K -= 2*(K/2);
    }
    if (K > 0) ans += K;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
l = raw_input().split()
N = int(l[0])
M = int(l[1])
nlist = []
list1 = []
for i in range(0, M):
    tmp = raw_input().split()
    a = int(tmp[0])
    b = int(tmp[1])
    if a == 1:
        list1.append(b)
        continue
    if b == N:
        nlist.append(a)
        continue
matched_list = list(set(list1) & set(nlist))
if len(matched_list) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 24676
import Control.Monad
import Text.Printf

main = do
  line <- readline getLine
  let aa = Point { x = line !! 0, y = line !! 1}
  let bb = Point { x = line !! 2, y = line !! 3}
  let l = Line aa bb
  q <- readLn
  input <- replicateM q getLine
  let xs = fmap (fmap (read :: String -> Double) . words) input
  let points = fmap (\e -> Point{x = e !! 0, y = e !! 1}) xs
  solve2 l points
{-
solve :: Line Double -> [Point Double] -> IO ()
solve l xs = do
  let result = fmap (\e -> (x $ res l (e !! 0) (e !! 1), y $ res l (e !! 0) (e !! 1))) xs
  mapM_  (\r -> (printf "%.8f %.8f\n" (fst r) (snd r))) result
    where res l x1 y1 = l `reflect` Point{x=x1,y=y1}
-}
solve2 :: Line Double -> [Point Double] -> IO ()
solve2 l xs = do
  let result = fmap (\e -> (x $ res l (x e) (y e), y $ res l (x e) (y e))) xs
  mapM_  (uncurry (printf "%.8f %.8f\n")) result
    where res l x1 y1 = l `reflect` Point{x=x1,y=y1}

readline :: (Read a) => IO String -> IO [a]
readline io = fmap (fmap read . words) io

rep :: (Read a) => Int -> ([a] -> IO ()) -> IO ()
rep n f = do
  input <- replicateM n (readline getLine)
  mapM_ f input

eps :: (Floating a) => a
eps = 1e-7

add :: (Ord a, Floating a) => a -> a -> a
add a b
  | abs (a + b) < eps * (abs a + abs b ) = 0.0
  | otherwise = a + b

data Point a = Point { x :: a, y :: a } deriving (Eq)
instance (Show a) => Show (Point a) where
  show(Point x y) = show x ++ " " ++ show y

toTuple :: Point a -> (a,a)
toTuple a = (x a,y a)

data Line a = Line {a :: Point a, b :: Point a}
instance (Show a) => Show (Line a) where
  show(Line a b) = show a ++ " " ++ show b

(^+) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^+ b =  Point (add (x a) (x b)) (add (y a) (y b))

(^-) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^- b = Point (add (x a) (-(x b))) (add (y a) (-(y b)))

(^*) :: (Floating a) => Point a -> a -> Point a
a ^* d = Point (x a * d) (y a * d)

dot :: (Floating a) => Point a -> Point a -> a
a `dot` b = x a * x b + y a * y b

project :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `project` p = a l ^+ (base ^* t)
  where base = b l ^- a l
        t = ((p ^- a l) `dot` base) / (base `dot` base)

reflect :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `reflect` p = p ^+ (((l `project` p) ^- p) ^* 2.0)

Measured memory_bytes: 5032
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main() {
	int count = 0;
	string s;
    cin >> s;
    string ss = s;
    reverse(ss.begin(), ss.end());
    rep(i, s.length() / 2){
    	if(s[i] != ss[i]){
        	count++;
        }
    }
    cout << count;
    
	
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll s = 1000001;
static const ll MOD = 1e9 + 7;

int main()
{
	ll h, w, n; cin >> h >> w >> n;

	map<pair<ll, ll>, ll> mp;
	ll total = (h - 2)*(w - 2);

	rep(i, 0, n) {
		ll a, b; cin >> a >> b;

		repe(y, -2, 0) {
			repe(x, -2, 0) {
				ll ny = a + y;
				ll nx = b + x;
				if (ny > 0 && ny <= h - 2 && nx > 0 && nx <= w - 2) {
					mp[make_pair(ny, nx)]++;
				}
			}
		}
	}

	map<ll, ll> ans;
	repe(i, 1, 9) {
		for (map<pair<ll, ll>, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
			if (it->second == i) {
				ans[i]++;
			}
		}
	}
	ll t = 0;
	repe(i, 1, 9) {
		t += ans[i];
	}
	ans[0] = total - t;

	repe(i, 0, 9) {
		cout << ans[i] << endl;
	}

	return 0;
}

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

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int b,f,r,v;
		int[][][] num = new int[4][3][10];
		for (int a=0;a<4;a++){
			for (int c=0;c<3;c++){
				for (int d=0;d<10;d++){
					num[a][c][d] = 0;
				}
			}
		}
		for (int a=0;a<n;a++){
			b=sc.nextInt();f=sc.nextInt();
			r=sc.nextInt();v=sc.nextInt();
			num[b-1][f-1][r-1] += v;
		}
		for (int a=0;a<4;a++){
			for (int c=0;c<3;c++){
				for (int d=0;d<10;d++){
					System.out.print(" "+num[a][c][d]);
				}
				System.out.println();
			}
			if (a<3){
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 21068
n = input()
x = map(int, raw_input().split())

MOD = 1000000007

j = 1
ans = 1
count = 0
for i in xrange(len(x)):
    if(x[i] >= 2*j-1):
        j += 1
        continue
    else:
        ans *= j
        count += 1

for i in xrange(len(x)-count):
    ans = ans*(i+1)%MOD

print ans

Measured memory_bytes: 11308
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std; 
          
int main(){
 double x1, x2, y1, y2;
 cin >> x1 >> y1 >> x2 >> y2;
        
 double dis=0;
 dis = sqrt( pow(x2-x1,2.0) + pow(y2-y1,2.0) );
      
 cout << fixed << setprecision(12) << dis << endl;

 return 0;
}


Measured memory_bytes: 3260
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a*b % 2 == 0)puts("Even");
	else puts("Odd");
	

	return(0);
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using ll = long long;
using namespace std;

const long long MOD = 1000000007;
const ll LINF = 1LL << 50;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

  int N;
  cin >> N;
  vector<ll> hn(100010, 0);
  vector<ll> dp(100010, LINF);
  
  REP(n,N) cin >> hn.at(n);

  dp.at(0) = 0;
  for (int n = 1; n < N; n++){
    chmin(dp.at(n), dp.at(n-1)+abs(hn.at(n)-hn.at(n-1)));
    if (n > 1) chmin(dp.at(n), dp.at(n-2)+abs(hn.at(n)-hn.at(n-2)));
  }

  cout << dp.at(N-1) << endl;

}


Measured memory_bytes: 1792
m, k = map(int, input().split())

if m == 1:
    if k == 0:
        ans = [0, 0, 1, 1]
    else:
        ans = []

elif k < 2 ** m:
    li = list(range(2 ** m))
    li.remove(k)
    ans = li + [k] + li[::-1] + [k]

else:
    ans = []

if ans:
    print(*ans)
else:
    print(-1)


Measured memory_bytes: 16360