akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    if(n>=30) Yes;
    else No;
}/*
./problem.exe
*/

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll a,b,c;
      cin>>a>>b>>c;
      if(a==b)
      cout<<c;
      if(b==c)
      cout<<a;
      if(a==c)
      {
          cout<<b;
      }
    } 
    return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[101][10001];
int main(void){
	int n;
	int box[100];
	int i,j;
	int MAX;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&box[i]);
	for(i=0;i<=n;i++){
		for(j=0;j<=10000;j++){
			dp[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<=10000;j++){
			dp[i+1][j+box[i]]=max(dp[i+1][j+box[i]],dp[i][j]+box[i]);
		}
	}
	MAX=0;
	for(i=0;i<=10000;i++)	if(dp[n][i]%10!=0)MAX=max(MAX,dp[n][i]);
	printf("%d\n",MAX);
	return 0;
}

Measured memory_bytes: 4096
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
X = max(a, *x)
dp = [[[0 for k in range(n*X+1)] for j in range(n+1)]for i in range(n+1)] #full((n+1, n+1, n*X+1), 0)
dp[0][0][0] = 1
for j in range(n+1):
    for k in range(n+1):
        for s in range(n*X+1):
            if j == k == s == 0: continue
            if j >= 1 and s < x[j-1]: dp[j][k][s] = dp[j-1][k][s]
            elif j >= 1 and k >= 1 and s >= x[j-1]: dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
            else: dp[j][k][s] = 0
print(sum([dp[n][k][k*a] for k in range(1, n+1)]))

Measured memory_bytes: 97244
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

struct edge{int to, cost;};

class Graph
{
public:
    int V;
    vector<vector<edge>> G;

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
    }

    void add_edge(int from, int to, int cost){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, int cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    void dfs(int &n, int &d, bools &used, int v, int g){
        n++;
        d += g;
        used[v] = true;
        REP(k, G[v].size()) if(!used[G[v][k].to]) dfs(n, d, used, G[v][k].to, g + 1);
    }

};

signed main(){

    int N; cin >> N;
    vector<Pii> D(N);
    REP(i, N){
        cin >> D[i].first;
        D[i].second = i;
    }
    Sort(D); Reverse(D);

    vec g(N, -1);
    map<int, set<int>> par;
    vector<Pii> ans(0);
    
    REP(i, N){
        int d = D[i].first;
        int v = D[i].second;
        int cnt = 1;
        for(int c: par[d]){
            cnt += g[c];
            ans.push_back(Pii(v, c));
        }
        g[v] = cnt;
        par[d - (N - 2 * cnt)].insert(v);
    }

    Graph G(N);
    REP(i, ans.size()){
        G.add_edge2(ans[i].first, ans[i].second, 0);
    }
    int n = 0, d = 0;
    bools used(N, false);
    G.dfs(n, d, used, D[0].second, 0);
    if(n == N && ans.size() == N - 1 && D[0].first == d){
        REP(i, N - 1) cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
    }else{
        cout << -1;
    }


    return 0;
}

Measured memory_bytes: 29680
#include <iostream>
#include <string>
using namespace std;
int h,w;
char a[52][52];
int d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int f(int x,int y)
{
    int x1,y1;
    int flag=0;
    for(int i=0;i<4;i++)
    {
        x1=x+d[i][0];y1=y+d[i][1];
        if(x1>=0&&x1<h&&y1>=0&&y1<w)
        if(a[x1][y1]=='#') {flag=1;break;}
    }
    return flag;
}
int main()
{
    int flag;
    cin>>h>>w;
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    cin>>a[i][j];
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    {
        if(a[i][j]=='#') flag=f(i,j);
        if(flag==0) {cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
def factorial(n, mod):
    fac = [0] * (n + 1)
    inv = [0] * (n + 1)
    fac[0], inv[0] = 1, 1
    for i in range(1, n + 1):
        fac[i] = fac[i-1] * i % mod
        inv[i] = inverse(fac[i], mod)
    return fac, inv

def inverse(a, mod):
    a %= mod # 除数が正なら正になる
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod # 除数が正なら正になる

mod = 10 ** 9 + 7
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    quit()
n = (x + y) // 3
if x < n or y < n:
    print(0)
    quit()

m = min(x, y) - n
fac, inv = factorial(n, mod)
print(fac[n] * inv[n-m] * inv[m] % mod) # nCm


Measured memory_bytes: 83892
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define ld long double
#define inf 1000000000
using namespace std;
#define N 205
#define mod 998244353
int n,pw[N],ans;
struct node{ int x,y; }a[N];
int main(){
	scanf("%d",&n);
	pw[0]=1; rep (i,1,n) pw[i]=2ll*pw[i-1]%mod;
	ans=(pw[n]+mod-1-n)%mod;
	rep (i,1,n) scanf("%d%d",&a[i].x,&a[i].y);
	rep (i,1,n) rep (j,i+1,n){
		int sum=0;
		rep (k,j+1,n)
			if ((a[i].y-a[j].y)*(a[j].x-a[k].x)==(a[i].x-a[j].x)*(a[j].y-a[k].y)) sum++;
		ans=(ans+mod-pw[sum])%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ankit_2305 cerr<<"\nTime taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<" sec\n";
#define START clock_t
#define TIMER time_p=clock();
#define ll long long

#define MOD 1000000007

using namespace std;

int a[100001], b[100001], c[100001], N;
ll dp[100001][3];

ll solve(int n, int last){
	if(n > N)
		return 0;
	if(dp[n][last] != 0)
		return dp[n][last];
	ll res = 0;
	if(last != 0)
		res = max(res, a[n] + solve(n+1, 0));
	if(last != 1)
		res = max(res, b[n] + solve(n+1, 1));
	if(last != 2)
		res = max(res, c[n] + solve(n+1, 2));
	return dp[n][last] = res;
}

int main(){
    START TIMER
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	while(t--){
		cin>>N;
		for(int i=1;i<=N;i++)
			cin>>a[i]>>b[i]>>c[i];
		ll ans = max(a[1] + solve(2, 0), b[1] + solve(2, 1));
		ans = max(ans, c[1] + solve(2, 2));
		cout<<ans<<"\n";
	}
    ankit_2305
    return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	string s;
	cin >> s;
	ll n = s.size();

	Array ans;
	char pre = s[0];
	ll con = 0;
	REP(i, n) {
		if (s[i] == pre) {
			con++;
		}
		else {
			ans.push_back(con);
			con = 1;
		}
		pre = s[i];
	}
	if (con > 0) ans.push_back(con);

	cout << ans.size()-1 << endl;

	return 0;
}

Measured memory_bytes: 1480
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll sum=0;
  rep(i,n){
    if(i==0) sum+=abs(a[i]-0);
    else sum+=abs(a[i]-a[i-1]);
    if(i==n-1) sum+=abs(a[i]);
  }
  rep(i,n){
    ll ans=sum;
    if(i==0){
      ans-=abs(a[i]-0)+abs(a[i]-a[i+1]);
      ans+=abs(a[i+1]-0);
      cout << ans << endl;
    }
    else if(1<=i&&i<=n-2){
      ans-=abs(a[i]-a[i-1])+abs(a[i]-a[i+1]);
      ans+=abs(a[i+1]-a[i-1]);
      cout << ans << endl;
    }
    else{
      ans-=abs(a[i]-a[i-1])+abs(a[i]-0);
      ans+=abs(a[i-1]-0);
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 1664
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3*1e5+10;
typedef long long ll;
int a[N],ans[N];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  ll sum=0,sum1=0;
  for(int i=1;i<=n;i++) sum+=a[i];
  for(int i=2;i<=n;i+=2) sum1+=a[i];
  ans[1]=sum-2*(sum1);
  for(int i=2;i<=n;i++) ans[i]=2*a[i-1]-ans[i-1];
  for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
int main()
{
    int a[30000]={0},b[30000]={0},flg[30000]={0};
    int i,j,k;
    int seito,list,cnt=0;
    while(scanf("%d",&seito)!=EOF)
    {
        scanf("%d",&list);
        if(seito==0&&list==0)break;
        flg[1]=1;
        for(i=1;i<=list;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
        }
        for(j=1;j<100;j++)
        {
        for(k=1;k<=15000;k++)
        {
            if(flg[a[k]]==1)flg[b[k]]=2;
            else if(flg[a[k]]==2&&flg[b[k]]!=2)flg[b[k]]=3;
        }
        for(k=1;k<=15000;k++)
        {
            if(flg[b[k]]==1&&a[k]!=1)flg[a[k]]=2;
            else if(flg[b[k]]==2&&a[k]!=1&&flg[a[k]]!=2)flg[a[k]]=3;
        }
        }
        for(i=2;i<20000;i++)
        {
            if(flg[i]==2||flg[i]==3)
            {
                //printf("%d\n",i);
                cnt++;
            }
        }
        printf("%d\n",cnt);
        cnt=0;
        for(i=0;i<30000;i++)
        {
            a[i]=0;
            b[i]=0;
            flg[i]=0;
        }
    }
    return 0;
}

Measured memory_bytes: 960
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;


int main(){
 int h,w; cin>>h>>w;
 int count=0;
 char v[h+2][w+2];
 REP(i,h+2){
   REP(j,w+2){

     if(i>=1&&i<=h&&j>=1&&j<=w)
     cin>>v[i][j];
     else v[i][j]='.';
   }
 }
  REP(i,h+2){
   REP(j,w+2){
     if(v[i][j]=='.')count++;
     else{
       if(v[i-1][j]=='#'||v[i+1][j]=='#'||v[i][j-1]=='#'||v[i][j+1]=='#')
       count ++;
     }
     }

   }
 if(count==(h+2)*(w+2))cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
}

Measured memory_bytes: 256
s = input()
l = len(s)
ans = int(s)

for bit in range(1<<l-1):
    plus = []
    for i in range(l-1):
        if 1<<i & bit:
            plus.append(i)
    
    if plus:
        a = 0
        b = 0
        for i in range(len(plus)):
            a = b
            b = plus[i] + 1
            ans += int(s[a:b])
        ans += int(s[b:])

print(ans)

Measured memory_bytes: 3060
import sys

input = sys.stdin.readline


def main():
    s = input().strip()
    print(
        "Yes"
        if all([c in ("R", "U", "D") for c in s[::2]])
        and all([c in ("L", "U", "D") for c in s[1::2]])
        else "No"
    )


if __name__ == "__main__":
    main()


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

int main()
{
  string s;
  cin>>s;
  
  int n=s.size();
  
  int count=0;
  
  if(n%2!=0)
  {
    for(int i=n/2+1;i<n;i++)
    {
      if(s.at(i)!=s.at(n-(i+1)))
      {
        s.at(i)=s.at(n-(i+1));
        count++;
      }
    }
  }
  else
  {
    for(int i=n/2;i<n;i++)
    {
      if(s.at(i)!=s.at(n-1-i))
      {
        //cout<<s.at(i)<<" "<<s.at(n-1-i)<<endl;
        s.at(i)=s.at(n-1-i);
        count++;
      }
    }
  }
  cout<<count<<endl;
}
        

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to,cost;
};

struct Data{
	Data(int arg_node_id,int arg_ball_state,int arg_total_cost){
		node_id = arg_node_id;
		ball_state = arg_ball_state;
		total_cost = arg_total_cost;
	}
	bool operator<(const struct Data &arg) const{
		return total_cost > arg.total_cost;
	}
	int node_id,ball_state,total_cost;
};

int N,M,L,K;
int POW[8],min_cost[50][10][128],index[50][128],exist_ball[50];
vector<Info> G[50];


void func(){

	for(int i = 0; i < N; i++)G[i].clear();

	int from,to,cost;
	for(int i = 0; i < M; i++){
		scanf("%d %d %d",&from,&to,&cost);
		from--;
		to--;
		G[from].push_back(Info(to,cost));
		G[to].push_back(Info(from,cost));
	}

	int start,goal;
	scanf("%d %d",&start,&goal);
	start--;
	goal--;

	for(int i = 0; i < N; i++)exist_ball[i] = -1;

	int tmp;
	for(int i = 0; i < L; i++){
		scanf("%d",&tmp);
		tmp--;
		exist_ball[tmp] = i;
	}

	for(int i = 0; i < N; i++){
		for(int state = 0; state < POW[L]; state++)index[i][state] = 0;
	}

	for(int i = 0; i < N; i++){
		for(int a = 0; a < K; a++){
			for(int state = 0; state < POW[L]; state++)min_cost[i][a][state] = BIG_NUM;
		}
	}

	priority_queue<Data> Q;

	int first_state;

	if(exist_ball[start] != -1){
		first_state = POW[exist_ball[start]];
	}else{
		first_state = 0;
	}
	min_cost[start][index[start][first_state]++][first_state] = 0;

	int next_node,next_state;

	for(int i = 0; i < G[start].size(); i++){
		next_node = G[start][i].to;

		if(exist_ball[next_node] != -1){
			next_state = first_state|POW[exist_ball[next_node]];
		}else{
			next_state = first_state;
		}
		if(index[next_node][next_state] >= K)continue;

		Q.push(Data(next_node,next_state,G[start][i].cost));
	}


	while(!Q.empty()){

		if(index[Q.top().node_id][Q.top().ball_state] >= K){
			Q.pop();
			continue;
		}

		min_cost[Q.top().node_id][index[Q.top().node_id][Q.top().ball_state]++][Q.top().ball_state] = Q.top().total_cost;

		for(int i = 0; i < G[Q.top().node_id].size(); i++){
			next_node= G[Q.top().node_id][i].to;

			if(exist_ball[next_node] != -1){
				next_state = Q.top().ball_state|POW[exist_ball[next_node]];
			}else{
				next_state = Q.top().ball_state;
			}

			if(index[next_node][next_state] >= K)continue;

			Q.push(Data(next_node,next_state,Q.top().total_cost+G[Q.top().node_id][i].cost));
		}
		Q.pop();
	}

	if(min_cost[goal][K-1][POW[L]-1] == BIG_NUM){
		printf("NA\n");
	}else{
		printf("%d\n",min_cost[goal][K-1][POW[L]-1]);
	}
}


int main(){

	for(int i = 0; i < 8; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d %d %d %d",&N,&M,&L,&K);
		if(N == 0 && M == 0 && L == 0 && K == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 41160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    int A, B, C; cin>>A>>B>>C;
    int K; cin>>K;
    for(int a=0; a<=K; a++){
        for(int b=0; b<=K; b++){
            for(int c=0; c<=K; c++){
                if(a+b+c==K){
                    if(A*pow(2, a) < B*pow(2, b) && B*pow(2, b) < C*pow(2, K-a-b)){
                        cout<<"Yes"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 4004
package main

import "fmt"

func main() {
    var N, v, min, max int
    var rate [9]int

    fmt.Scanf("%d", &N)

    for i := 0; i < N; i++ {
        fmt.Scanf("%d", &v)
        if v >= 3200 {
            rate[8]++
        } else {
            rate[v/400] = 1
        }
    }
    for i := 0; i < 8; i++ {
        if rate[i] > 0 {
            min++
        }
    }
    max = min + rate[8]
    if min == 0 {
        min = 1
    }
    fmt.Printf("%d %d\n", min, max)
}

Measured memory_bytes: 512
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,d,k;

int main()
{
	n=read(); k=read(); d=read(); n=abs(n);
	ll x=n/d;
	if(k<=x)
	{
		n-=d*k;
		cout<<n<<endl;
	}
	else
	{
		n%=d; k-=x;
		if(k%2==0) cout<<n<<endl;
		else cout<<d-n<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] dataA = new int[N+1];
    int[] dataB = new int[N+1];
    boolean t = true;
    for(int i=0;i<M;i++){
      int s = sc.nextInt();
      int c = sc.nextInt();
      if(N>1&&s==1&& c==0) {
    	  t = false;
      }
      if(dataB[s]==0){
        dataA[s]=c;
        dataB[s]++;
      }else{
        if(dataA[s] ==c){
          dataB[s]++;
        }else{
          t = false;
          break;
        }
      }
    }
   if(t ==false){
     System.out.print("-1");
     
   }else if(N==1 && dataB[1]==0){
	   System.out.print("0");		 
   }else{
     for(int i =1 ;i<N+1;i++){
    	  if(dataB[i] ==0 && i!=1 &&N>1){
    		       dataA[i]=0;
    		  }else if(dataB[i] ==0 && i==1 && N>1) {
    			  dataA[i]=1;
       }
       System.out.print(dataA[i]);
     }
   }
    
  }
}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

void clr(auto &a,int n){
  a.clear();
  a.resize(n);
}

void unq(auto &a){
  sort(all(a));
  a.resize(unique(all(a))-a.begin());
}

const int N=200005;

void solve(){
	int n,k,q;
	cin>>n>>k>>q;
	vi a(n);
	cin>>a;
	int ans=2e9;
	for(int x=0;x<n;x++){
		vi zz2;
		int cr=0;
		vector<vi>zz;
		debug(x);
		for(int j=0;j<n;j++){
			if(a[j]<a[x]){
				if(cr){
					zz.pb(zz2);
					zz2.clear();
				}
				cr=0;
			}
			else{
				zz2.pb(a[j]);
				cr++;
			}
		}
		if(cr){
			zz.pb(zz2);
		}
		debug(x);
		vi an;
		for(auto &i:zz){
			sort(all(i));
			debug(i,i.size()-k+1);
			for(int j=0;j<((int)i.size()-k+1);j++){
				an.pb(i[j]);
			}
		}
		debug(x);
		sort(all(an));
		if(an.size()<q){
			continue;
		}
		ans=min(ans,an[q-1]-a[x]);
	}
	cout<<ans;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //~cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main() {
	int N, D, X, i, flag, ans;
	ans = 0;
	cin >> N >> D >> X;
	for (i = 0;i < N;i++) {
		cin >> flag;
		ans += (D+flag-1)/flag;
	}
	cout << ans+X << endl;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size();
    return 0;
}


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

using namespace std;

int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  long long int w, h, x, y;
  long long int ans1;
  string dec = ".0 "; // &delimit
  int ans2 = 0;

  cin >> w >> h >> x >> y;
  if ((w%2 == 1) && (h%2 == 1)) {
    dec = ".5 ";
  }
  if ((w/2 == x && w%2 == 0) && (h/2 == y && h%2 == 0)) {
    ans2 = 1;
  }
  ans1 = w * h / 2;

  cout << ans1 << dec << ans2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
  	int A, B;
  	cin >> A >> B;
  	cout << (A - 1) * (B - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    for(int i=1;i<=(ty-sy);i++)printf("U");
    for(int i=1;i<=(tx-sx);i++)printf("R");
    for(int i=1;i<=(ty-sy);i++)printf("D");
    for(int i=1;i<=(tx-sx);i++)printf("L");
    printf("L");
    for(int i=1;i<=(ty-sy)+1;i++)printf("U");
    for(int i=1;i<=(tx-sx)+1;i++)printf("R");
    printf("D");
    printf("R");
    for(int i=1;i<=(ty-sy)+1;i++)printf("D");
    for(int i=1;i<=(tx-sx)+1;i++)printf("L");
    printf("U\n");
    return 0;
}



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

using namespace std;

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

  vector<int> A;
  int sum = 0;
  for(int i = 0;i < N;++i){
    int temp;
    cin>>temp;
    A.push_back(temp);
    sum += temp;
  }

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

  if(sum % 2 == 0){
    sum = sum / 2;
  }
  else{
    for(int e : A){
      if(e % 2 != 0){
        sum = sum - e;
        break;
      }
    }
    sum = sum / 2;
  }
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

//-----end of template-----//

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<i64> h(n);
	for(int i = 0; i < n; ++i) cin >> h[i];
	vector<i64> dp(n + 10, INF<int>);
	dp[0] = 0;
	for(int i = 0; i < n; ++i){
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
		if(i != n - 1) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int w = Integer.parseInt(br.readLine());
		int n = Integer.parseInt(br.readLine());
		
		int[] arr = new int[w + 1];
		for (int i = 1; i <= w ; i++) {
			arr[i] = i;
		}
		
		String line;
		while ((line = br.readLine()) != null) {
			String[] ab = line.split(",");
			int a1 = Integer.parseInt(ab[0]);
			int b1 = Integer.parseInt(ab[1]);
			int temp = arr[a1];
			arr[a1] = arr[b1];
			arr[b1] = temp;
		}

		for (int i = 1; i <= w ; i++) {
			System.out.println(arr[i]);
		}
	}

}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int INF = 1001001001;
int N, M, X;
int C[20], A[20][20];
int sum[20];

int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::cin >> N >> M >> X;

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

      for(int j=0;j<M;++j){
          std::cin >> A[i][j];
      }
  }

  int res = INF;

  for(int i=0;i<(1<<N);++i){
      memset(sum, 0, sizeof(sum));

      int cost = 0;

      for(int j=0;j<N;++j){
          if(i >> j & 1){
              cost += C[j];
              for(int k=0;k<M;++k){
                  sum[k] += A[j][k];
              }
          }
      }

      if(std::all_of(sum, sum + M, [&](int x){return x >= X;})){
          res = std::min(res, cost);
      }
  }

  if(res == INF){
      res = -1;
  }

  std::cout << res << std::endl;
}


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

int main ()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
    int n; cin >> n;
    vector<int> price(n);
    for(int i = 0; i < n; i++) cin >> price[i];
    long long stock = 0, money = 1000;
    for(int i = 0; i < n-1; i++) {
        if(price[i] < price[i+1]) {
            stock += money / price[i];
            money -= (money / price[i]) * price[i];
        }
        if (price[i] > price[i+1]){
            money += stock * price[i];
            stock = 0;
        }
    }
    cout << money + stock * price[n-1];
}

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

int main() {
	bool flag=false;
	char word;
	std::vector<char> vowel{'a','i','u','e','o'};

	std::cin >> word;

	for (int i = 0; i < 5; i++) {
		if (word == vowel[i]) {
			flag = true;
		}
	}

	if (false == flag) {
		std::cout << "consonant" << std::endl;
	}
	else {
		std::cout << "vowel" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
check=dict()
N,b,d=0,[],0
#ttfは235、chaはabc

def dfs_sub(n,ttf,cha):
    global check,d

    #-1ずつしていく場合
    check[0]=min(check[n]+n*d,check[0])

    #最寄りまで-してく場合
    x1,x2=n//ttf,n%ttf
    if x1 in check:
        if check[x1]>check[n]+x2*d+cha:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)
    else:
        check[x1]=check[n]+x2*d+cha
        dfs(x1)

    #最寄りまで+1してく場合
    x1,x2=n//ttf+1,ttf-n%ttf
    if x1 in check:
        if check[x1]>check[n]+x2*d+cha:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)
    else:
        check[x1]=check[n]+x2*d+cha
        dfs(x1)


def dfs(n):
    global b,check,d
    for i,j in zip([2,3,5],b):
        dfs_sub(n,i,j)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])


Measured memory_bytes: 122424
#include<cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
int n;
LL sum, a[N];
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i ++){
		scanf("%I64d", &a[i]);
		sum += a[i];
	}
	int f1 = sum&1;
	int f2 = n&1;
	if(f1 == 1 && f2 == 1){
		int f = -1, c, win = 1, ff;
		LL g;
		while(f == -1){
			c = 0, ff = 0;
			for(int i = 0; i < n; i ++){
				if(a[i] & 1) c ++;
				if(a[i] == 1) ff = 1;
			}
			if(c == 1 && ff != 1){
				if(a[0] & 1) a[0] --;
				g = a[0];
				for(int i = 1; i < n; i ++){
					if(a[i] & 1){
						a[i] --;
					}
					g = __gcd(g, a[i]);
				}
				for(int i = 0; i < n; i ++){
					a[i] /= g;
				}
				sum --;
				sum /= g;
				if(sum & 1) win ^= 1;
				else f = win;
			}else{
				f = win;
			}
		}
		puts(f?"Second":"First");
		return 0;
	}
	puts(f1 == f2?"Second":"First");
}

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

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	int n  ;
	cin >> n ;
	map<int,int> mp ;
	int sum = 0 ; 
	for(int i = 0 ;i < n ; ++i)
	{
		int a ; 
		cin >> a ;
		mp[a]++ ;
		sum += a; 
	} 
	int q ; 
	cin >> q ;
	for(int i = 0 ; i < q ;++i) 
	{
		int b ,c ; 
		cin >> b >> c ; 
		sum -= b*mp[b] ; 
		sum += c*mp[b] ; 
		cout << sum << '\n' ; 
		mp[c] += mp[b] ; 
		mp.erase(b) ; 
	}



}

Measured memory_bytes: 7492
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	long long N, K;
	cin >> N >> K;
	long long tmp = N / K;
	tmp++;
	tmp *= K;
	tmp -= N;
	tmp = abs(tmp);
	long long ans = min(tmp, N % K);
	cout << ans << endl;
}

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

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

	if ((a == b + c) || (b == a + c) || (c == a + b)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import * as fs from 'fs';

 const input = fs.readFileSync('/dev/stdin', 'utf8');
//const input = fs.readFileSync('./input.txt', 'utf8');

_b(input);

function _b(input: string) {
  const [ABC, _K] = input.split('\n');
  const K = parseInt(_K);
  const [A, B, C] = ABC.split(' ').map((s) => parseInt(s));
  // console.log(A, B, C, K);

  // A は B の何倍か？を 2^n で表す
  const n = Math.max(0, Math.ceil(Math.log2((A + 1) / B)));
  const b = B * 2 ** n;

  // b は C の何倍か？を 2^m で表す
  const m = Math.max(0, Math.ceil(Math.log2((b + 1) / C)));

  // console.log(n, m, b);

  console.log(n + m <= K ? 'Yes' : 'No');
}


Measured memory_bytes: 29688
#!/usr/bin/ruby
N=gets.to_i
r=1.step(N-2,2).flat_map{|i|[[0,i],[i,0]]}
r+=N.times.select{|i|(i+N)%2==0}.flat_map{|i|[[N-1,i],[i,N-1]]}
1.step(N-2,3){|j|
	1.step(N-2){|i|
		r<<[i,j] if (i+j)%2==1
	}
}
p r.size
puts r.map{|e|e*' '}

Measured memory_bytes: 52604
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
A = str(input()).split()
a = int(A[0])
b = int(A[1])
c = int(A[2])
# S = [[0 for i in range(W)] for j in range(H)]
#unko=0

if(a+b+c>21):
  print("bust")
else:
  print("win")

#print(ans)



Measured memory_bytes: 13340
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int N;
  cin >> N;
  int B[200000] = {0};
  for (int n = 1; n < N; n++)
  {
    int A;
    cin >> A;
    B[A - 1]++;
  }
  for (int n = 0; n < N; n++)
  {
    cout << B[n] << endl;
  }
  return 0;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct dian
{
    int x,y;
} a[10];
double b[10][10];
int n;
int main()
{
    memset(b,0,sizeof(b));

    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        cin>>a[i].x>>a[i].y;
    }
    double ans=0;
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            double s=0;
             s=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
            ans=ans+s*2;
        }
    }
    ans=ans*1.0/n;
    printf("%.6lf\n",ans);
}


Measured memory_bytes: 256
def solve():
    def recur(i, s):
        if not i < length:
            return sum(map(int, s.split("+")))

        ans1 = 0
        if not i == length - 1:
            ans1 = recur(i + 1, s + S[i] + '+')
        ans2 = recur(i + 1, s + S[i])
        return ans1 + ans2

    S = input()
    length = len(S)

    # print('S, len', S, length)

    return recur(0, '')


if __name__ == '__main__':
    res = solve()
    print(res)


Measured memory_bytes: 39664
//【ライブラリここから】
// 1. 入力の容易化（https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8）
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//【ライブラリここまで】

fn main() {
    input! {
        n: i64,
        c_tmp: String,
    }
    let c = c_tmp.as_bytes();
    let mut w_total_count: i64 = 0;
    let mut r_total_count: i64 = 0;
    for item in c.clone() {
        if *item == 'W' as u8 {
            w_total_count += 1;
        } else {
            r_total_count += 1;
        }
    }
    let mut left_w: i64 = 0;
    let mut right_r: i64 = r_total_count;
    let mut result = n;
    if w_total_count == 0 || r_total_count == 0 {
        println!("{}", 0);
        return;
    }
    for item in c.clone() {
        if *item == 'W' as u8 {
            left_w += 1;
        } else {
            right_r -= 1;
        }
        let tmp = if left_w >= right_r { left_w } else { right_r };
        if result > tmp {
            result = tmp;
        }
    }
    println!("{}", result);
    return;
}


Measured memory_bytes: 2396
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;


int main() {

	ll n, m, p;
	while(cin >> n >> m >> p){
		if(n == 0 && m == 0 && p == 0) break;
		vector<ll> vec(n);
		ll sum = 0;
		rep(i, n){
			cin >> vec[i];
			sum += vec[i];
		}
		
		if(vec[m-1] == 0) cout << 0 << endl;
		else cout << sum * (100 - p) / (vec[m-1]) << endl;
	}

	return 0;
}

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

int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int count=0;
  if(A>K)
    count+=K;
  else if(A+B>K)
    count+=A;
  else
    count+=A-(K-(A+B));
  cout<<count<<endl;
}

Measured memory_bytes: 3636
s = int(input())
count = 0

# 考え：初めに５の面を上にし、６、５、６、５の面を繰り返し上にしていくと良さそう
# 方針：while中、奇数回目にsから６を引く、偶数回目にsから５を引くことを繰り返す計算を行う

# この方法だとsが大きい場合、計算に時間がかかる
"""
while s > 0:
    if count == 0 or count % 2 != 0:
        s = s - 6
    else:
        s = s - 5

    count += 1
"""

# 方針：6、5、6、5...の繰り返しなので11で割った商と
#       余りが6以下なら1回サイコロを動かし、11以外なら2回動かせば良い

count = s // 11 * 2

if s % 11 == 0:
    pass
elif s % 11 <= 6:
    count += 1
else:
    count += 2

print(count)

Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    string s;
    cin >> s;
    vector<string> s1;
    s1 = split(s,",");
    cout << s1[0] << " " << s1[1] << " " << s1[2];
}



template<typename T>
void swap(T* a,T* b)
{
    int c = *a;
    *a = *b;
    *b = c;
}



vector<string> split(string str, string separator) 
{
    if (separator == "") 
        return {str};
    vector<string> result;
    string tstr = str + separator;
    long long unsigned int l = tstr.length(), sl = separator.length();
    string::size_type pos = 0, prev = 0;
    
    for (;pos < l && (pos = tstr.find(separator, pos)) != string::npos; prev = (pos += sl))
    {
        result.emplace_back(tstr, prev, pos - prev);
    }
    return result;
}


Measured memory_bytes: 256
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll R,G,B,N;
    cin>>R>>G>>B>>N;
    ll ans=0;
    for (int i = 0; i <=3000; ++i)
    {
    	for (int j = 0; j <=3000; ++j)
    	{
    		if(N-i*R-j*G>=0 && (N-i*R-j*G)%B==0)
    		{
    			ans++;
    		}
    	}
    }
    cout<<ans<<'\n';
}



Measured memory_bytes: 256
n, x = map(int, input().split())
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
if n > 1:
    d = gcd(abs(xlis[0]-x), abs(xlis[1]-x))
    for i in range(2, n):
        d = gcd(d, abs(xlis[i]-x))
    print(d)
else:
    print(abs(xlis[0] - x))

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
 using namespace std;
 int main() {
	 int N;
	  cin >> N;
	  vector<int> a(N);
	  int sum = 0;
	  for (int i = 0; i < N; ++i) 
	  {
		  cin >> a[i];
		  sum += a[i];
	  }
	  int mini = sum;
	  int prefix_sum = 0;
	  for (int i = 0; i < N; ++i)
	  {
		  prefix_sum += a[i];
		  if (mini < abs(prefix_sum - (sum - prefix_sum)))
			  mini = mini;
		  else
		  mini = abs(prefix_sum - (sum - prefix_sum)); 
	  }
	  cout << mini << endl;
	  return 0;
}

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

using namespace std;

int main(){
  string S; cin >> S; int cnt1 = 0; int cnt2 = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == '0'){cnt1++;}
    else{cnt2++;}}
  
  cout << min(cnt1,cnt2) * 2 << endl; return 0;}

Measured memory_bytes: 512
sa = input()
sb = input()
sc = input()

a = 1
b = 0
c = 0

now = sa[0]

while a != len(sa)+1 and b != len(sb)+1 and c != len(sc)+1:

    if now == 'a':
        if a == len(sa):
            print("A")
            exit()
        now = sa[a]
        a += 1
    elif now == 'b':
        if b == len(sb):
            print("B")
            exit()
        now = sb[b]
        b += 1
    elif now == 'c':
        if c == len(sc):
            print("C")
            exit()
        now = sc[c]
        c += 1


Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<=(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int k,x,i;
  cin >> k >> x;

  for(i=x-k+1;i<=x+k-1;i++){
      cout << i;
      if(i==x+k-1){
          cout << endl;
      }
      else{
          cout << " ";
      }
  }
  return 0;
}


Measured memory_bytes: 256