akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define N 1000010

using namespace std;
int n, m, c[N], num[N], tree[N], booll[N], nnn[N], ww;
struct node {
	int l, r, pos;
}ask[N];

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int lowbit(int x) {
	return x & (-x);
}

void change(int x, int k) {
	while (x <= n) {
		c[x] += k;
		x += lowbit(x); 
	}
}

int query(int x) {
	int ans = 0;
	while (x) {
		ans += c[x];
		x -= lowbit(x);
	}
	return ans;
}
bool cmp (node a, node b) {
	return a.r < b.r;
}
int main() {
	scanf("%d",&n);
	scanf("%d",&m);
//	n = read();
	for (int i = 1; i <= n; i++) scanf("%d",&num[i]);//num[i] = read();
//	m = read();
	for (int i = 1; i <= m; i++){
		//ask[i].l = read(), ask[i].r = read(), ask[i].pos = i;
		scanf("%d%d",&ask[i].l, &ask[i].r);
		ask[i].pos = i;
	}
	sort(ask + 1, ask + 1 + m, cmp);
	int next = 1;
	for (int i = 1; i <= m; i++) {
		for (int j = next; j <= ask[i].r; j++){
			if (booll[num[j]]) change(booll[num[j]], -1);
			change(j, 1), booll[num[j]] = j;
		}
		next = ask[i].r + 1;
		nnn[ask[i].pos] = query(ask[i].r)- query(ask[i].l - 1);
	}
	for (int i = 1; i <= m; i++) printf("%d\n", nnn[i]);
	return 0;
}

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

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

    string s;
    cin >> s;
    if(s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 3588
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    r = len(s)
    res = 0
    for i in range(r//2):
        if s[i] != s[-(i+1)]:
            res += 1
    print(res)



if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		int cnt=0;
		int c=a+b;
		while(c){
			c/=10;
			cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 3068
memo = {}

n = int(input())
for i in range(n):
    s = input().strip()
    if s not in memo:
        memo[s] = 1
    else:
        memo[s] += 1

n = int(input())
for i in range(n):
    s = input().strip()
    if s not in memo:
        memo[s] = -1
    else:
        memo[s] -= 1

res =  max(memo.values())
if res<0:
    res = 0

print(res)

Measured memory_bytes: 3064
import copy
N = int(input())
X = [int(i) for i in input().split()]
Y = copy.deepcopy(X)
Y = sorted(Y, key= lambda x: -x)

c = int(N/2)

for i in range(N):
    a = X[i]
    if a >= Y[c-1]:
        print(Y[c])
    else:
        print(Y[c-1])

Measured memory_bytes: 26052
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const ll MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

double ans = 0;

void dis(double x1,double y1,double x2,double y2){
     ans += sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

void solve(){
    double n;cin >> n;
    vector<double>a(n);
    vector<double>b(n);
    vector<int>p(n);
    for(int i = 0;i<n;i++) p[i] = i;
    for(int i = 0;i<n;i++) cin >> a[i] >> b[i];
    do{
        for(int i = 0;i<n-1;i++)
            dis(a[p[i]],b[p[i]],a[p[i+1]],b[p[i+1]]);
    }
    while(next_permutation(p.begin(),p.end()));
    double fac = 1;
    for(int i = 1;i<=n;i++) fac *= i;
    cout << fixed << setprecision(10) <<(ans/fac);

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3804
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#define int long long
using namespace std;
const int INF = 10000000000000;

signed main() {
	int N;
	cin >> N;
	vector<int> s(N);
	for (int i = 0; i < N; i++) cin >> s[i];
	int wa = 0;
	int small = INF;
	for (int i = 0; i < N; i++) wa += s[i];
	if (wa % 10 == 0) {
		for (int i = 0; i < N; i++) {
			if (s[i] % 10 != 0 && small > s[i]) small = s[i];
		}
		if (small == INF) cout << "0" << endl;
		else cout << wa - small << endl;
	}
	else cout << wa << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  ll a,n,m;
  cin >> a >> n >> m;
  vector<ll> vec;
  for(ll i=1; pow(i,n)<=1e9; i++){
    ll temp = 1;
    for(ll j=0; j<n; j++){
      temp *= i;
    }
    vec.push_back(temp);
  }
  ll cnt = 0;
  for(ll i=0; i<vec.size(); i++){
    if(vec[i] <= m){
      ll t = vec[i];
      ll sum=0;
      while(t){
        sum += t%10;
        t /= 10;
      }
      sum += a;
      ll x = sum;
      for(ll j=0; j<n-1; j++){
        sum *= x;
      }
      if(sum == vec[i]){
        cnt++;
      }
    }else{
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3372
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int h,w,n;
  scanf("%d%d%d",&h,&w,&n);
  vvi ps(h);
  rep(i,n) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    ps[a].pb(b);
  }
  rep(i,h) sort(rng(ps[i]));
  int ans = h;
  int l = 0;
  rep(i,h) {
    if (sz(ps[i])) {
      int x = ps[i][0];
      if (x < l) {
        cout<<i<<endl;
        return 0;
      }
      l = min(l+1,x);
    } else {
      l = min(l+1,i+1);
    }
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 11136
from itertools import compress

def solve(RSP, T, K):
    w = [True] * K
    for i, (t, tt) in enumerate(zip(T, T[K:])):
        w.append(True if t != tt else not w[i])
    return sum(map(lambda t: RSP[t], compress(T, w)))

def main():
    _, K = list(map(int, input().split()))
    RSP = dict(zip('spr', map(int, input().split())))
    T = input()
    print(solve(RSP, T, K))

if __name__ == '__main__':
    main()

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define mod 998244353
#define int long long
#define m_k make_pair
using namespace std;
const int N=2*1e5+100;
int n,dp[N],cnt[N],ans;
vector <int> e[N];
struct robot
{
	int x,d;
}sh[N];
priority_queue <int,vector<int>,greater<int> > q;
bool cmp(robot a,robot b)
{
	return a.x<b.x;
}
void dfs(int x)
{
	dp[x]=1;
	for (int i=0;i<(int)e[x].size();i++)
	{
		int u=e[x][i];
		dfs(u);
		dp[x]=(dp[x]*dp[u])%mod;
	}
	dp[x]=(dp[x]+1)%mod;
}
signed main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	  scanf("%lld%lld",&sh[i].x,&sh[i].d);
	sort(sh+1,sh+1+n,cmp);
	q.push(n);
	for (int i=n-1;i>=1;i--)
	{
		while (sh[i].x+sh[i].d-1>=sh[q.top()].x && !q.empty())
		{
			e[i].push_back(q.top());
			cnt[q.top()]++;
			q.pop();
		}
		q.push(i);
	}
	ans=1;
	for (int i=1;i<=n;i++)
	{
		if (cnt[i]==0)
		{
			dfs(i);
			ans=(ans*dp[i])%mod;
		}
	}
	printf("%lld\n",ans);
}

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

#define REP(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;

// constexpr ll mod = 1e9+7;

ll N;
ll K;
vector<ll> A;

int solve(){
  if(K <= N){
    ll pre = 0;
    REP(i, K){
      pre = A[pre];
    }
    return pre;
  }
  ll pre = 0;
  REP(i, N){
    pre = A[pre];
  }
  K -= N;
  vector<ll> ans(N+1);
  set<int> st;
  ans[0] = pre;
  REP(i, N){
    pre = A[pre];
    ans[(i+1)%N] = pre;
    if(st.find(pre) != st.end()){
      break;
    }
    st.insert(pre);
  }
  ll mod = st.size();
  return ans[K % mod];
}
int main(){
  cin >> N >> K;
  A.resize(N);
  REP(i, N){
    cin >> A[i];
    A[i]--;
  }
  cout << solve() +1 << endl;
}


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

using namespace std;
using llong = long long;
using ullong = unsigned long long;

int a[100000];
int main(){
  int n,k;
  cin >> n >> k;
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  int cnt = 1;

  int i;
  for(i=k;i<=n;i+=k-1){
    cnt++;
  }
  if(i==n+k-1) cnt--;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<class T> inline bool ch11000(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; }


map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

ll fac[110000], finv[110000], inv[110000];
 
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 110000; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int N;
ll M;

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

  COMinit();
  map<ll, int> mp = prime_factor(M);

  ll ans = 1LL;

  if (N == 1) {
    cout << ans << "\n";
    return 0;
  }

  for (auto itr = mp.begin(); itr != mp.end(); ++ itr) {
    int k = itr->second;

    //cout << k << "\n";
    //cout << N-1 << "\n";
    //cout << COM(k + N-1, k) << "\n";

    ans *= COM(k + N-1, k);
    ans %= MOD;
  }

  cout << ans << "\n";

}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi A(n);
  ll sum=0;
  vi yaku;
  for(auto &a:A){cin>>a;sum+=a;}
  A.pb(-llINF);
  sort(ALL(A));
  for(int i=1;i<=sqrt(sum);i++){
    if(sum%i==0){
      yaku.pb(sum/i);
      if(i!=1)
	yaku.pb(i);
    }
  }
  sort(ALL(yaku));
  ll ans=1;
  for(int i=0;i<yaku.size();i++){
    ll cnt=0;
    auto lb=upper_bound(ALL(A),yaku[i]);
    --lb;
    ll num=*lb;
    ll po=0;
    ll rui[555]={};
    ll rui2[555]={};
    vector<pair<ll,ll>>pll;
    for(int j=1;j<=n;j++){
      ll ff=A[j]/yaku[i];
      ll n1=ff*yaku[i];
      ll n2=(ff+1)*yaku[i];
      if(A[j]-n1==0)continue;
      pll.pb(mp(n2-A[j],A[j]-n1));
    }
    sort(ALL(pll));
    for(int kk=0;kk<pll.size();kk++){
      rui[kk+1]=rui[kk]+pll[kk].F;
      rui2[kk+1]=rui2[kk]+pll[kk].S;
    }
    if(pll.size()==0){
      ans=max(ans,yaku[i]);
    }
    // cout<<yaku[i]<<endl;
    // for(auto a:pll)
    //cout<<a.F<<" "<<a.S<<endl;
    for(int kk=1;kk<=pll.size();kk++){
      //if(yaku[i]==7)
      //cout<<rui[kk]<<" "<<rui2[pll.size()]-rui2[kk]<<endl;
      if(rui[kk]==rui2[pll.size()]-rui2[kk]){
	if(rui[kk]<=k)
	  ans=max(ans,yaku[i]);
	break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000
main()
{

    long long i,j,k,l,m,n,o,q,p;
   cin>>m>>n>>p;
   j=m/n;
   if(m%n>0)j++;
   cout<<j*p<<endl;
    return 0;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
ll targetnum(ll n)
{
    ll ret = 1ll << (ll)floor(log2(n * 2));
    return ret;
}

int main()
{
    ll n;
    cin >> n;
    ll a[n];
    map<ll, ll> mp;
    rep(i, n)
    {
        ll t;
        cin >> t;
        a[i] = t;
        mp[t]++;
    }
    sort(a, a + n, greater<ll>());
    ll ans = 0;
    rep(i, n)
    {
        if (mp[a[i]] == 0)
            continue;
        ll t = targetnum(a[i]) - a[i];
        if (mp[t] > 0 + (t == a[i] ? 1 : 0))
        {
            ans++;
            mp[t]--;
            mp[a[i]]--;
        }
    }

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

Measured memory_bytes: 27008
#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(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    int h=0,w=0,c=0,d=0,n,m,k,ans=0,y;
    string s,s2;
    char tmp;
    cin >> s >> s2;

    for(int i=0; i<s.size();i++){
        if(s==s2){
            cout << "Yes" <<endl;
            return 0;
        }
        tmp = s[0];
        rep(i,s.size()){
            s[i] = s[i+1];
        }
        s[s.size()-1] = tmp;
    }
    cout << "No" <<endl;
    return 0;
}


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

int n;

int main()
{
    int c = 0;
    int ans = 0;
    scanf("%d",&n);
    int t = n;
    while(t)
    {
        t/=10;
        c++;
    }
    for(int i = 1; i < c; i+=2)
    {
        ans += pow(10,i)-pow(10,i-1);
    }
    if(c%2!=0)
        ans += n-pow(10,c-1)+1;
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

int main()
{
    int A, B, C;
    cin>>A>>B>>C;
    if((B-A)==(C-B))
    {
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
    int n,i,a=0;
    double d;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(i % 2 != 0){
            a++;
        }
    }
    d = (float) a / n;
    printf("%.10lf\n",d);
    return 0;
}


Measured memory_bytes: 256
from collections import deque
from copy import deepcopy


def bfs(maze, s):
    que = deque()
    que.append(s)
    nx = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    while que:
        x, y, c = que.popleft()
        if maze[x][y] != ".":
            continue
        maze[x][y] = c
        for u, v in nx:
            que.append((x + u, y + v, c + 1))
    ll = sum(maze, [])
    s = set(ll) - {"#"}

    return max(s)


def main():
    h, w = map(int, input().split())
    wall = ["#"] * (w + 2)
    maze = [wall]
    road = []
    for i in range(1, h + 1):
        line = ["#"] + list(input()) + ["#"]
        maze.append(line)
        for j, k in enumerate(line):
            if k == ".":
                road.append((i, j, 0))
    maze.append(wall)

    ans = 0
    for p in road:
        m = deepcopy(maze)
        ans = max(ans, bfs(m, p))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
using namespace std;
#define lli long long int

int main() {
    lli x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    if(x/k >= d)
    cout<<x-k*d<<endl;
    else{
        lli rem = k - (x/d);
        lli ans = x - ((x/d) * d);
        if(rem&1)
        cout<<min(abs(ans+d),abs(ans-d))<<endl;
        else
        cout<<abs(ans)<<endl;
    }
	return 0;
}

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

namespace ans
{
  long double val=0.0;
}

int main()
{
  int n;
  cin>>n;
  if(n%2==0)
  {
    ans::val=0.5;
  }
  else
  {
    ans::val=(long double)(n/2+1)/n;
  }
  cout<<ans::val<<endl;
  
  return 0;
}


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

int main(void) {
    int i, len, N, R, B;
    char S[110];
    scanf("%d", &N);
    scanf("%s", &S);
    len = strlen(S);
    R = 0; B = 0;
    for (i=0;i<len;i++) {
        if (S[i] == 'R') R++;
        else B++;
    }
    if (R>B) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var hexls = Console.ReadLine().Split(' ');
            var X = hexls[0][0];
            var Y = hexls[1][0];
            string ret;
            if(X < Y)
            {
                ret = "<";
            }else if(X == Y)
            {
                ret = "=";
            }
            else
            {
                ret = ">";
            }
            Console.WriteLine(ret);
        }
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  
  int ans = 0;
  while(true){
    bool odd = false;
    for(int i = 0; i < n; i++){
      if(a[i] % 2 != 0) odd = true;
    }
    
    if(odd) break;
    
    for(int i = 0; i < n; i++){
      a[i] /= 2;
    }
    ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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 main() {
    input! {
        n: i32,
        a: i32
    }
    let rest = n % 500;
    println!("{}", if rest <= a { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include<iostream>
#include<malloc.h>
using namespace std;

typedef struct
{
	int num;
	char ch;
}*elem ,el;

void print(elem a, int n);
void print(elem a,int n)
{
	for (int i = 0; i < n; i++)
	{
		if (i > 0)
			cout << ' ';
		cout << a[i].ch<<a[i].num;
	}
	cout << endl;
}

int BubbleSort(elem a, int n)
{
	int m = 0;
	el t ;
	int flag = n-1;
	int k=0;
	for (int i = 0; i < n-1; i++)
	{
		for (int j = 0; j < flag; j++)
		{
			if (a[j].num > a[j+1].num)
			{
				t = a[j];
				a[j] = a[j+1];
				a[j+1] = t;
				m++;
				k = j + 1;
			}
		}
		flag = k;
	}
	return m;
}


int selectSort(elem a, int n)
{
	int m = 0;
	int min,k;
	el t;
	for (int i = 0; i < n-1; i++)
	{
		min = a[i].num;
		k = i;
		for (int j = i + 1; j < n; j++)
		{
			if (a[j].num < min)
			{
				min = a[j].num;
				k = j;
			}	
		}
		if (min != a[i].num)
		{
			t = a[k];
			a[k] = a[i];
			a[i] = t;
			m++;
		}	
	}
	return m;

}
int main()
{
	elem a=NULL,b=NULL;
	a = (elem)malloc(sizeof(el) * 100);
	b = (elem)malloc(sizeof(el) * 100);
	int n = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].ch;
		cin >> a[i].num;
		b[i] = a[i];

	}
	selectSort(a, n);
	BubbleSort(b, n);
	bool flag = 1;
	print(b, n);
	cout << "Stable" << endl;
	print(a, n);
	for (int i = 0; i < n; i++)
	{
		if (b[i].ch != a[i].ch || b[i].num != a[i].num)
		{
			cout << "Not stable" << endl;
			flag = 0;
			break;
		}
	}
	if (flag)
		cout << "Stable" << endl;
	return 0;
}



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

int main()
{
	double d;
	cin >> d;
	double res = d / sqrt(2) * 2;
	for (int i = 0; i <= floor(d); i++){
		double x = i, y = sqrt(d * d - i * i);
		if (y < 1.0){
			res = max(res, x + 1);
		}
	}
	printf("%.20f\n", res);
}

Measured memory_bytes: 3204
#include <stdio.h>
#include <math.h>

typedef struct{
double x;
double y;
}P;

void kock(int n,P p1,P p2){
    if (n == 0){
        return;
    }

    // p1, p2 から s, t, u を計算

    P s,t,u;
    double te = M_PI * 60.0 / 180.0;

    s.x=(2*p1.x+p2.x)/3;
    s.y=(2*p1.y+p2.y)/3;

    t.x=(p1.x+2*p2.x)/3;
    t.y=(p1.y+2*p2.y)/3;

    u.x=(t.x-s.x)*cos(te)-(t.y-s.y)*sin(te)+s.x;
    u.y=(t.x-s.x)*sin(te)+(t.y-s.y)*cos(te)+s.y;

    kock(n-1,p1,s);
    printf("%.8f %.8f\n",s.x,s.y);
    kock(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    kock(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    kock(n-1,t,p2);
}

int main(){
    P a,b;
    int n;

    scanf("%d",&n);

    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;

    printf("%.8f %.8f\n",a.x,a.y );
    kock(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y );

    return 0;
}



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

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

  // 出力
  if(N % 2 == 1){
    cout << (N+1)/2 << endl;
  } else {
    cout << N/2 << endl;
  }
  

  return 0;
}


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

#define MAXN 100000
int N,Root;
vector<int> G[MAXN+5];

int dfs(int u,int fa){//0黑 1百 -1必胜
	if(u!=Root&&G[u].size()==1)
		return 0;
	int cnt=0;
	for(int i=0;i<int(G[u].size());i++){
		int v=G[u][i];
		if(v!=fa){
			int tmp=dfs(v,u);
			if(tmp==-1)
				return -1;
			cnt+=tmp==0;
		}
	}
	if(cnt>=2)
		return -1;
	if(u==Root)
		return cnt!=1;
	return cnt==1;
}

int main(){
	scanf("%d",&N);
	for(int i=1;i<=N-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=N;i++){
		if(G[i].size()==1){
			Root=i;
			break;
		}
	}
	puts(dfs(Root,-1)?"First":"Second");
}


Measured memory_bytes: 5760
S = input()
# S.reverse()
S = S[::-1]
#dream, dreamer, erase, eraser
headers = ["resare","esare","remaerd","maerd"]

result = True
while True:
    if S=="":
        result = True
        break
    result = False
    for header in headers:
        if S.startswith(header):
            S = S[len(header):]
            result = True
    if not result:
        break

if result:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
H,W=map(int,input().split())
c = []
for i in range(10):
    c.append(list(map(int,input().split())))

A = []
for i in range(H):
    A.append(list(map(int,input().split())))

c2 = [[0 for _ in range(10)]for _ in range(10)]

for i in range(10):
    for j in range(10):
        c2[i][j] = c[i][j]+c[j][1]

d = []
for i in range(10):
    d.append(min(c2[i]))

for _ in range(10):
    c2 = [[0 for _ in range(10)]for _ in range(10)]
    for i in range(10):
        for j in range(10):
            c2[i][j] = c[i][j]+d[j]
    d = []
    for i in range(10):
        d.append(min(c2[i]))
su = 0
for i in range(H):
    for j in range(W):
        if A[i][j] >=0:
            su+=d[A[i][j]]
print(su)


Measured memory_bytes: 68148
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{

  private static int   in_N;
  private static int[] in_C;
  private static int[] in_S;
  private static int[] in_F;

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int cnt;
    int cnt_one;
    int ans;


    try
    {
      in_stream    = new BufferedReader(new InputStreamReader(System.in));
      in_str       = new String(in_stream.readLine());
      in_str_split = in_str.split(" ");

      in_N = Integer.parseInt(in_str_split[0]);
      in_N--;

      in_C  = new int[in_N];
      in_S  = new int[in_N];
      in_F  = new int[in_N];
      for(cnt=0; cnt<in_N; cnt++)
      {
        in_str       = new String(in_stream.readLine());
        in_str_split = in_str.split(" ");
        in_C[cnt]    = Integer.parseInt(in_str_split[0]);
        in_S[cnt]    = Integer.parseInt(in_str_split[1]);
        in_F[cnt]    = Integer.parseInt(in_str_split[2]);
      }


      for(cnt=0; cnt<in_N; cnt++)
      {
        ans = 0;
        for(cnt_one=cnt; cnt_one<in_N; cnt_one++)
        {
          ans = calcAapproximation(cnt_one, ans);
        }

        UtilLog.ans_ln("" + ans);
      }

      UtilLog.ans_ln("0");
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }



  private static int calcAapproximation
  (
    int i_index,
    int i_start
  )
  {
    int ret;
    int c;
    int s;
    int f;


    ret = 0;
    c   = in_C[i_index];
    s   = in_S[i_index];
    f   = in_F[i_index];

    if(i_start <= s)
    {
      ret = s + c;
    }
    else
    {
      ret = s + f;
      while(ret<i_start)
      {
        ret += f;
      }
      ret += c;
    }


    return ret;
  }


}


class UtilLog
{
  private static boolean is_debug_mode = false;



  public static void ans_ln
  (
    String i_message
  )
  {
    System.out.println(i_message);
  }



  public static void ans_f
  (
    String i_message
  )
  {
    System.out.printf(i_message);
  }



  public static void inf_ln
  (
    String i_message
  )
  {
    StackTraceElement[] stack;


    if(is_debug_mode)
    {
    stack = new Throwable().getStackTrace();

    System.out.println
      (
        String.format
          (
            "[inf][%s:%s():%5d]",
            stack[1].getClassName(),
            stack[1].getMethodName(),
            stack[1].getLineNumber(),
            i_message
          )
      );
    }
  }
}


Measured memory_bytes: 23764
L = list(input())

count = 0
m_count = 0
for i in L:
      if i == 'A' or i == 'C' or i == 'G' or i == 'T':
            count += 1
            if count >= m_count:
                  m_count = count
      else:
            count = 0

print(m_count)

Measured memory_bytes: 2940
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<string>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int k;
    cin >> s >> k;
    REP(i, s.size()) {
        if (s[i] != 'a' && 'z' - s[i] + 1 <= k) {
            k -= 'z' - s[i] + 1;
            s[i] = 'a';
            // D(k);
        }
    }
    if (k > 0) {
        s[s.size() - 1] = (s[s.size() - 1] - 'a' + k) % 26 + 'a';
    }
    cout << s << endl;
}


Measured memory_bytes: 576
#include<bits/stdc++.h>
#define assn(n,a,b) assert(n<=b && n>=a)
using namespace std;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,b) for(i=0;i<b;i++)
#define rep1(i,b) for(i=1;i<=b;i++)
#define pdn(n) printf("%d\n",n)
#define sl(n) scanf("%lld",&n)
#define sd(n) scanf("%d",&n)
#define pn printf("\n")
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
#define MOD 1000000007
LL mpow(LL a, LL n)
{LL ret=1;LL b=a;while(n) {if(n&1)
    ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
return (LL)ret;}
#define MAXK 100000
#define MAXN 1000000000
int ar[MAXK];
int get(int n, int k){
    int i=0;
    while(i<k and ar[i]<=n)i++;
    return n-i;
}
typedef unsigned long long int ULL;
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

bool isSafe(int r, int c, vector<vector<int> > arr) {
	int n = arr.size();
	int m = arr[0].size();
	return (r>=0 && r<n && c>=0 && c<m);
}

/////////////////////////////////////////////////////////////
bool diffSign(int a,int b) {
	return ((a>0 && b<0) || (a<0 && b>0));
}  

int main() 
{ 
	int n,l,r;
	int sum=0;
	cin>>n;
	while(n--) {
		cin>>l>>r;
		sum+=r-l+1;
	}
	cout<<sum;
	return 0; 
} 


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  if(S.find("RRR")!=string::npos)cout<<3<<endl;
  else if(S.find("RR")!=string::npos)cout<<2<<endl;
  else if(S.find("R")!=string::npos)cout<<1<<endl;
  else cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int cnt=700;
	string s;
	cin >> s;
	rep(i,3){
		if (s[i]=='o'){
			cnt += 100;
		}
	}
	cout << cnt << endl;
}

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

int main()
{
  vector<long long int> A(5);
  long long int N;

  cin >> N;
  for(int i=0; i<5; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  if(N % A[0] == 0){
    cout << 5 + (N / A[0]) - 1<< endl;
  }else{
    cout << 5 + (N / A[0]) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
   int stage[10][10]={0};
   int x,y,size;
   int i,j,k;
   int a=0,ans;
   int count=0;

   while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
   if(size == 0)break;
   if(size == 1 || size == 2 || size == 3){
        stage[x][y]+=1;
        if(x+1>=0 && x+1<=9)stage[x+1][y]+=1;
        if(x-1>=0 && x-1<=9)stage[x-1][y]+=1;
        if(y+1>=0 && y+1<=9)stage[x][y+1]+=1;
        if(y-1>=0 && y-1<=9)stage[x][y-1]+=1;
        if(size == 2 || size == 3){
            if(x+1>=0 && x+1<=9 && y+1>=0 && y+1<=9)stage[x+1][y+1]+=1;
            if(x+1>=0 && x+1<=9 && y-1>=0 && y-1<=9)stage[x+1][y-1]+=1;
            if(x-1>=0 && x-1<=9 && y+1>=0 && y+1<=9)stage[x-1][y+1]+=1;
            if(x-1>=0 && x-1<=9 && y-1>=0 && y-1<=9)stage[x-1][y-1]+=1;
            if(size == 3){
                if(y+2>=0 && y+2<=9)stage[x][y+2]+=1;
                if(y-2>=0 && y-2<=9)stage[x][y-2]+=1;
                if(x+2>=0 && x+2<=9)stage[x+2][y]+=1;
                if(x-2>=0 && x-2<=9)stage[x-2][y]+=1;
            }
        }
    }
    }
    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            if(stage[i][j]>0)count++;
            if(stage[i][j]>a)a=stage[i][j];
        }
    }
    ans=100-count;
    printf("%d\n%d\n",ans,a);
    return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#define N 100
void swap(int *, int *);

int main(){
  int n, flag=0, i, j;
  int A[N];
  int key;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  for(i=0; i<n; i++){
    for(j=n-1; j>=0; j--){
      if(A[j] < A[j-1]){
      swap(&A[j],&A[j-1]);
      flag++;
      }
    }
  }

  for(i=0; i<n; i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }

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

  return 0;
}

void swap(int *a,int *b)
{
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

void search(int sx,int sy,int tx,int ty){
	int x = sx;
	int y = sy;
	while(x< tx){
		cout << 'R';
		x++;
	}
	while(y<ty) {
		cout << 'U';
		y++;
	}
	while (x > sx)
	{
		cout << 'L';
		x--;
	}
	while (y>sy)
	{
		cout << 'D';
		y--;
	}
}

void search2(int sx,int sy,int tx,int ty){
	int x = sx;
	int y = sy - 1;
	cout << 'D';
	while(x< tx+1){
		cout << 'R';
		x++;
	}
	while(y<ty) {
		cout << 'U';
		y++;
	}
	cout << 'L';
	x--;
	cout << 'U';
	y++;

	while (x > sx-1)
	{
		cout << 'L';
		x--;
	}
	while (y>sy)
	{
		cout << 'D';
		y--;
	}
	cout << 'R';
}


int main(){
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty; 
	search(sx,sy,tx,ty);
	search2(sx,sy,tx,ty);
	return 0;
}

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

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

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

    cout << A * B / gcd(A, B);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100500];
void solve() {
	int n, m;
	cin >> m >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n - 1; i++) {
		a[i] = a[i + 1] - a[i];
	}
	sort(a, a + n - 1);
	int res = 0;
	for (int i = n - m - 1; i >= 0; i--) {
		res += a[i];
	}
	cout << res;
	// .   .      .         .            .                  .
	// 0   1      2         3            4
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}

Measured memory_bytes: 3988
# B - Buildings are Colorful!
# 全探索、BIT全探索
N, K = map(int, input().split())
A = list(int(x) for x in input().split())

def solve(idx):
    ret = 0
    tmpmax = A[0]
    for i in range(1, idx[-1]+1):
        if A[i] <= tmpmax:
            if i in idx:
                ret += tmpmax - A[i] + 1
                tmpmax += 1
        else:
            tmpmax = A[i]
    return ret

ans = 10**18
for i in range(1<<N):
    idx = []
    for j in range(N):
        if i>>j&1:
            idx.append(j)
    if len(idx)==K and idx[0]==0:
        ans = min(ans, solve(idx))

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define INF 1000000000000000000
#define PI 3.14159265359
#define ull unsigned long long
#define MYPOW_t int

ull compare_smallorder(const void *a, const void *b){return *(ull*)a - *(ull*)b;}

int main(){
    ull i,n,a[100002]={},ans=1;
    scanf("%lld",&n);
    for (i=0; i<n; i++){
        scanf("%lld",&a[i]);
        if (a[i]==0) {
            printf("%d",0);
            return 0;
        }
    }
    qsort(a, n, sizeof(a[0]), compare_smallorder);
    for (i=0; i<n; i++) {
        if (a[i]>INF/ans) {
            printf("%d",-1);
            return 0;
        }
        ans*=a[i];
    }
    printf("%lld",ans);
    return 0;
}




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

int main(void){
    int n,n_tmp,x=0;
    cin>>n;
    n_tmp = n;
    while( n_tmp > 0){
        x += n_tmp%10;
        n_tmp /= 10;
    }
    cout<<(( n%x == 0 )? "Yes": "No")<<endl;
}

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

template <class T>
inline void read(T &res)
{
	char ch;
	while (ch = getchar(), !isdigit(ch));
	res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
}

const int N = 20;
const int M = 1005;
const int S = 1 << 15;
const int mod = 1e9 + 7;
int ex[M], f1[S], f2[S], cnt1[S], cnt2[S], g[S];
int n, m, id; bool vis[N][N];

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

inline void dec(int &x, int y)
{
	x -= y;
	x < 0 ? x += mod : 0;
}

int main()
{
	read(n); read(m);
	ex[0] = 1;
	for (int i = 1, u, v; i <= m; ++i)
	{
		ex[i] = ex[i - 1];
		add(ex[i], ex[i - 1]);
		read(u); 
		read(v);
		vis[u][v] = vis[v][u] = true;
	}
	const int C = (1 << n) - 1;
	for (int i = 1; i <= C; ++i)
		for (int j = 1; j <= n; ++j)
			if (1 << j - 1 & i)
				for (int k = j + 1; k <= n; ++k)
					if ((1 << k - 1 & i) && vis[j][k])
						++cnt1[i];
	for (int i = 1; i <= C; ++i)
		for (int j = 1; j <= n; ++j)
			if (!(1 << j - 1 & i))
				for (int k = 1; k <= n; ++k)
					if ((1 << k - 1 & i) && vis[j][k])
						++cnt2[i], g[i] |= 1 << j - 1;
	f1[1] = 1;
	for (int i = 2; i <= C; ++i)
		if (i & 1)
		{
			f1[i] = ex[cnt1[i]];
			for (int j = i - 1 & i; j; j = j - 1 & i)
				if (j & 1)
					dec(f1[i], 1ll * f1[j] * ex[cnt1[i ^ j]] % mod);
		}
	f2[2] = 1;
	for (int i = 3; i <= C; ++i)
		if (i >> 1 & 1)
		{
			f2[i] = ex[cnt1[i]];
			for (int j = i - 1 & i; j; j = j - 1 & i)
				if (j >> 1 & 1)
					dec(f2[i], 1ll * f2[j] * ex[cnt1[i ^ j]] % mod);
		}
	int ans = ex[m];
	for (int i = 1; i <= C; ++i)
		if (i & 1)
		{
			int ti = C ^ i ^ g[i];
			for (int j = ti; j; j = j - 1 & ti)
				if (j >> 1 & 1)
					dec(ans, 1ll * f1[i] * f2[j] % mod * ex[m - cnt1[i] - cnt1[j] - cnt2[i] - cnt2[j]] % mod);
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  
  vector<P> p;
  p.push_back(P(1,1));
  int nowl=a[0];
  int nowh=a[0];
  int now=0;
  
  while(now<n){
    while(a[now]<=nowl&&now<n){
      nowl=a[now];
      now++;
    }
    if(n==now) break;
    nowh=a[now];
    
    
    while(a[now]>=nowh&&now<n){
      nowh=a[now];
      now++;
    }
    p.push_back(P(nowl,nowh));
    nowl=a[now-1];
  }
  ll ans=1000;
  for(P x:p){
    //cout<<x.fi<<" "<<x.se<<endl;
    ans=(ans/x.fi)*x.se+ans%x.fi;
  }
  
  cout<<ans<<endl;
}






Measured memory_bytes: 3636
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,a[200005],ans=0;
int32_t main(){
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }

ll mn=mod,mx=0;
for(ll i=0;i<n;i++)
{
    if(i==0){
        ans++;
    }else {
    if(a[i]<=mn){
        ans++;
    }
    }
    mn=min(mn,a[i]);
    mx=max(mx,a[i]);
}
cout<<ans<<endl;
}



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

int main () {
  string S;
  cin >> S;
  const int64_t num = S.size();

  int64_t ans = 0;
  int64_t count = (int)pow(2, num-1);

  for (int64_t tmp = 0; tmp < (1 << 10); tmp++) {
    if(count == tmp)
      break;
    bitset<10> b(tmp);

    int64_t sum = 0;
    string T = "";
    for (int64_t i = 0; i < num; i++) {

      if(b.test(0)){
        T += S.at(i);
	    sum += stol(T);
        T = "";
      }else{
      	T += S.at(i);
      }

      b = b >> 1;
    }
    if(T.size() > 0)
	  sum += stol(T);
    ans += sum;
  }

  cout << ans << endl;

}


Measured memory_bytes: 4112
sub u1{my$i=pop;
	$p[$i]=$p[$i]&&$p[$i]!=$i?u1($p[$i]):$i+0
}
sub u2{my$i=pop;
	$q[$i]=$q[$i]&&$q[$i]!=$i?u2($q[$i]):$i+0
}
($N,$K,$L)=split$",<>;
for(1..$K){
	($a,$b)=split$",<>;
	$a=u1($a+0);
	$b=u1($b+0);
	if($a!=$b){
		$p[$a]=$b
	}
}
for(1..$L){
	($a,$b)=split$",<>;
	$a=u2($a+0);
	$b=u2($b+0);
	if($a!=$b){
		$q[$a]=$b
	}
}
@s=map[u1($_),u2($_),$_],1..$N;
@s=sort{@$a[0]<=>@$b[0]||@$a[1]<=>@$b[1]}@s;
for($i=0;$i<$N;){
	$j=$i+1,$t=1;
	($a,$b)=@{$s[$i]};
	for(;($c,$d)=@{$s[$j]},$j<$N&&$a==$c&&$b==$d;++$j){
		++$t
	}
	for(;$i<$j;++$i){
		$ans[@{$s[$i]}[2]]=$t
	}
}
print$_,$"for@ans


Measured memory_bytes: 77048
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int a[100000];
ll sum[100000];

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    rep(i, n)scanf("%d", a+i);
    sort(a, a + i);
    sum[0] = a[0];
    rep1(i, n)sum[i] = sum[i - 1] + a[i];

    per(i, n - 1){
      if(sum[i] * 2LL < (ll)a[i + 1])break;
    }
    pri(n - i - 1);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>

int prime(long int n)
{
    if(n==2)
       return 1;
       
    else if(n%2==0 || n<2)
        return 0;
        
    else
      {
          long int i;
          for(i=3;i<=sqrt(n);i+=2)
            {
                if(n%i==0)
                    return 0; 
            }
            
            return 1;
             
      }
}
int main(void) {
	long int x;
	scanf("%ld",&x);
	long int i;
	for(i=x;;++i)
	  {
	      if(prime(i))
	         break;
	  }
	  printf("%ld\n",i);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    Abra_Ka_Dabra

    ll n, k;
    cin>>n>>k;
    vector<ll> x;
    x.push_back(0);
    int c = 0;
    while(n--){
        ll tmp;
        cin>>tmp;
        x.push_back(x[c++]+tmp);
    }
    for(int i=k, j=1; i<x.size()-1; i++,j++){

        ll term1 = x[i];
        term1 -= x[j-1];
        ll term2 = x[i+1];
        term2 -= x[j];

        if(term2>term1) cout<<"Yes\n";
        else cout<<"No\n";
    }


    return 0;
}


Measured memory_bytes: 5328