akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const double PI=3.14159265358979323846;

int main()
{
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  double angle1=m*6.0;
  double angle2=h*30.0+m/2.0;
  // cout<<angle1<<" "<<angle2<<endl;
  double angle=abs(angle1-angle2);
  // cout<<angle<<endl;
  if(angle>180.0)
    angle=360.0-angle;
  // cout<<angle<<endl;
  double ans=sqrt(a*a+b*b-2*a*b*cos((angle*PI)/180.0));
  cout<<fixed<<setprecision(20)<<ans;
}
         

Measured memory_bytes: 4212
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int x,y,z;cin>>x>>y>>z;
    x-=z;
    cout<<x/(z+y)<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int H,W;
int i, j;
    while(1){
    
    scanf("%d %d",&H,&W);
    if(H==0&&W==0){
        break;
    }
    for ( i = 0; i < H; i++ ){
        for ( j = 0; j < W; j++ ){
        if(i%2==0){
            if(j%2==1){
                printf(".");
            }
            else if(j%2==0){
                printf("#");
            }

        }
        if(i%2==1){
            if(j%2==1){
                printf("#");
            }
            else if(j%2==0){
                printf(".");
            }

        }
    }
    printf("\n");

}
printf("\n");

    }









    return 0;
}

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

#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair 
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"
const ll ll_MAX = 1922337203685;
const ll MOD = 998244353;
ll fast_expo(ll x,ll p){if(p==0) return 1;
    else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} 
    else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  
    else return gcd(b%a,a); }
    
int main()
{
    fast
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ll t_c; t_c = 1;
    // cin >> t_c;
    for(ll t_i=0; t_i<t_c; ++t_i){
        ll n; cin >> n;
        ll mat[n][n];
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j)
                cin >> mat[i][j];
        }

        ll dp[1<<n];
        fill_n(dp, 1<<n, -ll_MAX);

        dp[0] = 0;
     	vector<int> arr;
        for(int i = 1; i < (1<<n); ++i){
            int temp = i;
            arr.clear();
            for(int j = 0; j < n; ++j){
                if(temp&(1<<j))
                    arr.pb(j);
            }

            int x = arr.size();

            for(int j = 1; j < (1<<x)-1; ++j){
                int val1 = 0;
                for(int k = 0; k < x; ++k){
                    if(j&(1<<k)){
                        val1 += (1<<arr[k]);
                    }
                }

                int val2 = (i^val1);
                dp[i] = max(dp[i], dp[val1]+dp[val2]);
            }

            ll sum = 0;
            for(int j = 0; j < arr.size(); ++j){
                for(int k = j+1; k < arr.size(); ++k)
                    sum += mat[arr[j]][arr[k]];
            }

            dp[i] = max(dp[i], sum);
        }
        cout << dp[(1<<n)-1];
    }  
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  int n,a;
  cin>>n>>a;


  int ans = n%500 <= a;
  cout<<(ans? "Yes":"No")<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  ll n;
  cin >> n >> s;
  ll ans = 0;
  for (int i = 0; i < 1000; i++) {
    char d[3] = {'0' + i / 100, '0' + ((i / 10) % 10), '0' + (i % 10)};
    int cur = 0;
    for (int j = 0; j < n; j++) {
      if (s[j] == d[cur]) cur++;
      if (cur == 3) break;
    }
    if (cur == 3) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
N = int(input())
a = list(map(int, input().split()))

a.insert(0, 0)
b = [0 for _ in range(N+1)]

b[-1] = a[-1]
for i in reversed(range(N+1)):
    sum = 0
    for j in range(2, N+1):
        if i*j <= N:
            sum += b[i*j]
        else:
            break
    if sum%2 == a[i]:
        b[i] = 0
    else:
        b[i] = 1

ans = [str(i+1) for i, x in enumerate(b[1:]) if x == 1]
print(len(ans))
if len(ans) != 0:
    print(" ".join(ans))

Measured memory_bytes: 17844
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
vector<vector<ll>> dp(401,vector<ll>(401,LINF));
ll n ;
vector<ll> a;
vector<ll> rui;

ll f(int &l, int &r){
    if(l==0) return rui.at(r-1);
    return rui.at(r-1) - rui.at(l-1);
}

int main(){
    ll n ; cin >> n;
    a.resize(n);
    rui.resize(n);
    rep(i,n) cin >> a.at(i);
    rui.at(0) = a.at(0);
    for(int i=1;i<n;i++){
        rui.at(i) = rui.at(i-1) + a.at(i);
    }
    for(int i=0;i<n;i++){
        dp[i][i+1] = 0;
    }

    for(int width=2;width<=n;width++){
        for(int l=0;l<n;l++){
            int r = l+width;
            if(r>n) break;
            for(int m=l+1;m<r;m++){
                dp[l][r] = min(dp[l][r] , dp[l][m] + dp[m][r] + f(l,r));
            }
            //cout << dp[l][r] << endl;
        }
    }
    cout << dp[0][n] << endl;    
    return 0;
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(long long N, std::vector<long long> A) {
  unordered_set<ll> S;
  rep(i,N){
    S.insert(A[i]);
  }
  if(S.size()<N) cout << "NO" << endl;
  else cout << "YES" << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 12972
a,b = map(int,input().split())

list = []
if 100*a%8:
  x=int(a/0.08)+1
else:
  x=int(a/0.08)

if 100*(a+1)%8:
    y=int((a+1)/0.08)
else:
    y=int((a+1)/0.08)-1

    
for i in range(x, y+1):
    if b/0.1 <= i <(b+1)/0.1:
        list.append(i)

        
list = sorted(list)
if list:
    print(list[0])
else:
    print('-1')



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

int main() {
	map<int, long long>mp;
	int n; cin >> n;
	long long k; cin >> k;
	while (n--) {
		int num, cop; cin >> num >> cop;
		mp[num] += cop;
	}
	for (auto it : mp) {
		if (k <= it.second) return cout << it.first, 0;
		k -= it.second;
	}
	return 0;
}

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

int main() {
    int N, C, K;
    cin >> N >> C >> K;

    vector<int> t(N);
    for (auto& i : t) cin >> i;

    sort(t.begin(), t.end());
    vector<int> m;
    m.push_back(t[0]);
    for (int i = 1, count = 1; i < N; i++) {
        if (t[i] - m[m.size()-1] > K || count+1 > C) {
            m.push_back(t[i]);
            count = 1;
        } else {
            count++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 1276
#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 <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)

int count(int N)
{

        int cnt = 0;
        while (N)
        {
                cnt += N % 10;
                N /= 10;
        }
        return cnt;
}

int main()
{
        int N, Y;
        cin >> N >> Y;
        int x = -1, y = -1, z = -1;
        rep(i, Y / 10000 + 1)
        {
                rep(j, Y / 5000 + 1)
                {
                        // cout << i << ' ' << j << ' ' << Y / 1000 - 10 * i - 5 * j << endl;
                        if (i + j + (Y / 1000 - 10 * i - 5 * j) == N && Y / 1000 - 10 * i - 5 * j >= 0)
                        {
                                x = i;
                                y = j;
                                z = Y / 1000 - 10 * i - 5 * j;
                                break;
                        }
                }
        }
        printf("%d %d %d\n", x, y, z);

        return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
//#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<list>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
//llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int a,b;cin>>a>>b;cout<<gcd(a,b)<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int ll;

int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll cost[n]={0};
	cost[1]=abs(a[1]-a[0]);
	for(ll i=2;i<n;i++){
		cost[i]=INFINITY;
		for(ll j=1;j<=min(i,k);j++){
			cost[i]=min(cost[i],cost[i-j]+abs(a[i]-a[i-j]));
		}
	}
	//for(ll i=2;i<n;i++){
	//	cost[i]=min(cost[i-1]+abs(a[i]-a[i-1]),cost[i-2]+abs(a[i]-a[i-2]));
	//}
	//ll min=INFINITY;
	cout<<cost[n-1]<<endl;
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

vector < pp > V[N];
int T[N],H[N],n,m,i,x,y,z;

void f(int x){
    H[x] = 1;
    for(int y, i=0; i<V[x].size(); i++){
        if(!H[ y = V[x][i].st ]){
            T[y] = T[x] + V[x][i].nd;
            f(y);
        }
        else if(T[y] != T[x] + V[x][i].nd){
            puts("No"); exit(0);
        }
    }
}

signed main(){
    scanf("%d%d",&n,&m);
    for(; m-- ;){
        scanf("%d%d%d",&x,&y,&z);
        V[x].pb(mp(y,z));
        V[y].pb(mp(x,-z));
    }

    for(i=1;i<=n;i++){
        if(H[i]) continue;
        f(i);
    }

    puts("Yes");
    return 0;
}

Measured memory_bytes: 14720
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=2020,M=4040,P=1000000007,ny2=(P+1)/2;
int i,j,k,n,m,ch,ff,ans;
int a[200200],b[200200];
int s[M][M];
int C[M][M];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
int main() {
	R(n);
	for (i=1;i<=n;i++) {
		R(a[i]);R(b[i]);
		s[N-a[i]][N-b[i]]++;
	}
	for (i=1;i<M;i++) C[i][0]=C[0][i]=1;
	for (i=1;i<M;i++)
		for (j=1;j<M;j++) {
			s[i][j]=(s[i-1][j]+s[i][j-1]+s[i][j])%P;
			C[i][j]=(C[i-1][j]+C[i][j-1])%P;
		}
	for (i=1;i<=n;i++) ans=(ans+s[N+a[i]][N+b[i]])%P;
	for (i=1;i<=n;i++) ans=(ans+P-C[a[i]+a[i]][b[i]+b[i]])%P;
	ans=(ll) ans*ny2%P;
	printf("%d\n",ans);
}

Measured memory_bytes: 129280
#include <iostream>
#include <string>
#include <set>
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() << endl;
  return 0;
}


Measured memory_bytes: 19232
#include<iostream>
#include<functional>
#include<iomanip>
#include<vector>
#include<set>
#include<queue>
#include<utility>
#include<map>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>

#define LL long long
#define INT_MAX 2147483647

using namespace std;

struct SegmentTree {
private:
	int N;
	vector<LL> node;
	const long long DEFAULT = -9223372036854775807LL;
public:
	void init(int n) {
		node.clear();
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) node.push_back(DEFAULT);
	}
	void update(int i, long long x) {
		i += N - 1;
		node[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}
	long long maximum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r == -1) r = N;
		if (r <= a || b <= l) return DEFAULT;
		if (a <= l && r <= b) return node[k];
		return max(maximum(a, b, k * 2 + 1, l, (l + r) / 2), maximum(a, b, k * 2 + 2, (l + r) / 2, r));
	}
	long long m;
	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r == -1) {
			m = maximum(a, b);
			r = N;
		}
		if (r <= a || b <= l) return 99999999;
		if (r - l == 1) {
			if (node[k] == m) return l;
			else return 99999999;
		}
		if (a <= l && r <= b) {
			LL valueL = maximum(a, b, k * 2 + 1, l, (l + r) / 2);
			LL valueR = maximum(a, b, k * 2 + 2, (l + r) / 2, r);
			if (valueL >= valueR) return find(a, b, k * 2 + 1, l, (l + r) / 2);
			else return find(a, b, k * 2 + 2, (l + r) / 2, r);
		}
		return min(find(a, b, k * 2 + 1, l, (l + r) / 2), find(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};

int N, K;
int a[200000];
SegmentTree st;
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	st.init(N);
	for (int i = 0; i < N; i++) {
		st.update(i, a[i]);
	}
	int l = 0;
	for (int i = 0; i < N - K; i++) {
		int p = st.find(l, K+i+1);
		l = p + 1;
		//cout << K+i+1 << " " << p << endl;
		cout << a[p];
	}
	cout << endl;
	return 0;
}





Measured memory_bytes: 7800
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;
 
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
vector<int> g[100005];
int val[100005], sub[100005], ans[100005];
bool rev = 0;
void dfs1(int u, int p, int d){
    if(val[u] != -1){
        sub[u] = 1;
        if((d+rev)%2 != val[u]%2){
            printf("No\n");
            exit(0);
        }
    }
    for(int i=0;i<sz(g[u]);i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs1(v, u, d+1);
        sub[u] += sub[v];
    }
}
int L[100005], R[100005];
void dfs2(int u, int p, int d){
    L[u] = -2e6, R[u] = 2e6;
    if(val[u] != -1){
        L[u] = val[u];
        R[u] = val[u];
    }
    for(int i=0;i<sz(g[u]);i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs2(v, u, d+1);
        L[u] = max(L[u], L[v]-1);
        R[u] = min(R[u], R[v]+1);
    }
    if(L[u] > R[u]){
        printf("No\n");
        exit(0);
    }
    else if(val[u] != -1 && (val[u] < L[u] || val[u] > R[u])){
        printf("No\n");
        exit(0);
    }
    else if(val[u] == -1 && L[u] == R[u]){
        if((d+rev)%2 != (L[u]%2+2)%2){
            printf("No\n");
            exit(0);
        }
    }
}
void dfs3(int u, int p, int d, int l, int r){
    l = max(l, L[u]);
    r = min(r, R[u]);
    if(l == r) ans[u] = r;
    else if((l%2+2)%2 == (d+rev)%2) ans[u] = l;
    else ans[u] = l+1;
 
    l = ans[u];
    r = ans[u];
 
    for(int i=0;i<sz(g[u]);i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs3(v, u, d+1, l-1, r+1);
    }
}
int main(){
    int n, k;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) val[i] = -1;
    for(int i=1;i<=n-1;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].eb(b);
        g[b].eb(a);
    }
    scanf("%d", &k);
    int r = 0;
    for(int i=1;i<=k;i++){
        int v, p;
        scanf("%d%d", &v, &p);
        val[v] = p;
        r = v;
    }
    if(val[r]%2 == 1) rev = 1;
    dfs1(r, 0, 0);
    dfs2(r, 0, 0);
    dfs3(r, 0, 0, val[r], val[r]);
    printf("Yes\n");
    for(int i=1;i<=n;i++) printf("%d\n", ans[i]);
}

Measured memory_bytes: 19032
H, W = map(int,input().split())
L = []

def cange(x):
  if x == '.':
    return 0
  else:
    return 1

zerofill = [ '.' for _ in range(W+2)] 

L.append(zerofill)
for _ in range(H):
  L.append(['.']+list(input())+['.'])
L.append(zerofill)

for i in range(1,H+1):
  for j in range(1,1+W):
    if L[i][j] == '.':
      cnt = 0
      for x in [-1,0,1]:
        for y in [-1,0,1]:
          if not (x == 0 and y == 0):
            cnt += cange(L[i+x][j+y])
      print(cnt,end='')
    else:
      print('#',end='')
  print()

Measured memory_bytes: 3444
from collections import deque

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
    
A.sort()
D = deque()
for i in range(N):
    if i%4==0:
        D.append(A[i//2])
    elif i%4==1:
        D.appendleft(A[-1-(i-1)//2])
    elif i%4==2:
        D.appendleft(A[i//2])
    else:
        D.append(A[-1-(i-1)//2])
ans1 = 0
for i in range(N-1):
    ans1 += abs(D[i+1]-D[i])

A.sort(reverse=True)
D = deque()
for i in range(N):
    if i%4==0:
        D.append(A[i//2])
    elif i%4==1:
        D.appendleft(A[-1-(i-1)//2])
    elif i%4==2:
        D.appendleft(A[i//2])
    else:
        D.append(A[-1-(i-1)//2])
ans2 = 0
for i in range(N-1):
    ans2 += abs(D[i+1]-D[i])
    
print(max(ans1,ans2))

Measured memory_bytes: 57640
/* ***********************************************
Author        :yang12138
Created Time  :2017年04月26日 星期三 22时38分13秒
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)



int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
   	ll x,y; 
	scanf("%lld%lld",&x,&y);
	if(y>=x-1 && y<=x+1) printf("Brown\n");
	else printf("Alice\n");
    return 0;
}


Measured memory_bytes: 256
#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
#define INF 100000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

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

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

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



int H, W;
char maze[60][60];

int main () {
  cin >> H >> W;

  Rep(i, 60) {
    Rep(j, 60) {
      maze[i][j] = ' ';
    }
  }

  rep(i, H) {
    rep(j, W) {
      cin >> maze[i][j];
    }
  }

  bool ans = true;

  rep(i, H) {
    rep(j, W) {
      if (maze[i][j] == '#') {
        bool flg = false;
        Rep(k, 4) {
          char tmp_char = maze[i + dx[k]][j + dy[k]];
          if (tmp_char == '#') {
            flg = true;
            break;
          }
        }
        if (!flg) {
          ans = false;
          break;
        }
      }
    }
  }

  cout << (ans ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int x, y, min = 1000000, max = -1000000;
    long long sum = 0;
    scanf("%d", &x);
    for (int i = 1; i <= x; i++)
    {
        scanf("%d", &y);
        if (y < min)
            min = y;
        if (y > max)
            max = y;
        sum = sum + y;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2108
import sys
readline = sys.stdin.readline

def main():
    A, V = map(int, readline().rstrip().split())
    B, W = map(int, readline().rstrip().split())
    T = int(readline())

    v = V - W
    if v <= 0:
        print('NO')
        return
    
    if abs(A - B) / v > T:
        print('NO')
    else:
        print('YES')

if __name__ == '__main__':
    main()

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

const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(auto &i : v)
    cin >> i;
  ll int partSum = 0;
  for(int i = 0; i < n; i++) {
      partSum += v[i] % mod;
      partSum %= mod;
  }
  ll int totSum = 0;
  for(int i = 0; i < n - 1; i++) {
      partSum -= v[i] % mod;
      partSum = (partSum + mod) % mod;
      totSum += ((v[i] % mod) * (partSum % mod)) % mod;
      totSum %= mod;
  }
  cout << totSum << '\n';
}
  

Measured memory_bytes: 4060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextIntSlice(size int) []int {
	re := make([]int, size)
	for i := 0; i < size; i++ {
		re[i] = nextInt()
	}
	return re
}

func max(a []int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func min(a []int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	a := make([]int, m)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		a[i], b[i] = nextInt(), nextInt()
	}

	ans := make([]int, n)
	for _, v := range a {
		ans[v-1]++
	}
	for _, v := range b {
		ans[v-1]++
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    for (size_t i = 0; i < s.size(); i++) {
        cout << s.at(i);
        if (i == 3)
            cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<ctype.h>
#include<string>

using namespace std;

#define OUT cout <<
#define IN cin >>
#define E << endl;
#define FOR(i,a,b) for(int i = a;i < b;i++)


string str;


int main(){
	getline(cin, str);


	FOR(i,0,str.size()){
		str[i] = (char)toupper((int)(str[i]));
	}
	/*
	OUT str;
	
	while(IN str){
		OUT  " ";
		FOR(i,0,str.size()){
			str[i] = (char)toupper((int)(str[i]));
		}
		OUT str;
	}	
	OUT "\n";
	*/

	OUT str E
}

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

int main()
{
	int n;
	scanf("%d",&n);
	int ans = 0;
	while(n--) {
		int a,b;
		scanf("%d%d",&a,&b);
		ans += b - a + 1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mp make_pair
#define pb push_back
#define ins insert
#define si size()
#define E exp(1.0)
#define fixed cout.setf(ios::fixed)
#define fixeds(x) setprecision(x)
#pragma GCC optimize(2)
using namespace std;
inline ll read(){ll s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;}void put1(){ puts("Yes") ;}void put2(){ puts("No") ;}
void debug(){printf("T   A   T\n");}void put3(){ puts("-1"); }ll qpf(ll a, ll b, ll p)
{ll ret = 0;while(b){if(b & 1) ret = (ret + a) % p;a = (a + a) % p;b >>= 1;}
return ret % p ;}ll qp(ll a, ll n, ll p){ll ret = 1;while(n){if(n & 1) ret = qpf(ret, a, p);
a = qpf(a, a, p);n >>= 1;}return ret % p ;}//��=acos(L/2R);
//void say(){ cout<<"I CAN AC"<<endl;}

const int manx=1e6+5;
const double eps =1e-8;


 int main()
 {
 	ll n,a,b,ans=0;
 	cin>>n>>a>>b;
 	if(n%(a+b)==0) ans=(n/(a+b))*a;
 	else{
 		ans+=(n/(a+b))*a;
 		if(n%(a+b)>a) ans+=a;
 		else ans+=(n%(a+b));
	 }
	cout<<ans<<endl;
	return 0;
 }


Measured memory_bytes: 256
import sys

N,M=list(map(int,input().split()))
num = [None] * N
for i in range(M):
    s,c=list(input().split())
    if num[int(s)-1] is not None and num[int(s)-1] != c:
        print('-1')
        sys.exit()
    else:
        num[int(s)-1] = c
if N > 1 and num[0] == '0':
    print('-1')
    sys.exit()
else:
    for i in range(N):
        if num[i] == None:
            num[i] = '0' if i > 0 or N == 1 else '1'
print(''.join(num))


Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


# いっこ入力
n =int(input())

# n行の数をリストへ
a = [int(input()) for i in range(n)] 
a = sorted(a)
b=[0]*(n//2)
c=[0]*(n//2)
answer = 0
for i in range(0,n//2):
    b[i] = a[i]
    c[i] = a[n-i-1]
answer += c[0] - b[0]
for i in range(1,n//2):
    answer += c[i-1] - b[i]
    answer += c[i] - b[i-1]


if n % 2 == 1:
    answer += max(c[-1]-a[(n-1)//2],a[(n-1)//2]-b[-1])

print(answer)


Measured memory_bytes: 26420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, ans = 0; cin>>n;
    string s; cin>>s;
    vector<int> w_idx, r_idx;
    for(int i=0;i<n;i++){
        if(s[i] == 'W'){
            w_idx.push_back(i);
        }else{
            r_idx.push_back(i);
        };
    }

    sort(w_idx.rbegin(), w_idx.rend());

    while(1){
        if(!w_idx.size() || !r_idx.size()) break;
        if(w_idx.back() >= r_idx.back()) break;
        ans++;
        w_idx.pop_back();
        r_idx.pop_back();
    }
    cout<<ans;
}

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

int main(){
  int a;
  cin >> a;
  int b;
  cin >> b;
  int c;
  cin >> c;
  int d;
  cin >> d;
  int e;
  cin >> e;
  int k;
  cin >> k;
  
  int x=a+k;
  
  if(b>x||c>x||d>x||e>x){
    cout << ":(" << endl;
  }
  
  else{
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
//二部マッチング問題と捉えて解く
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>

#define N_MAX 100
using namespace std;

struct edge {int to,cap,rev;};


//G[0]=s,G[1~N]=R,G[N+1~2N]=B,G[2N+1]=t;
vector<edge> G[2*N_MAX+2];
bool used[2*N_MAX+2];

void add_edge(int from,int to){
  G[from].push_back( (edge){to,1,G[to].size()} );
  G[to].push_back( (edge){from,0,G[from].size()-1} );
}

int dfs(int v,int t,int f){
  if(v==t) return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,1);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(){
  int i,k,N;
  int rc[N_MAX][2]={0},bc[N_MAX][2]={0};
  
  cin >> N;
  for(i=0;i<N;i++){
    cin >> rc[i][0] >> rc[i][1];
  }
  for(i=0;i<N;i++){
    cin >> bc[i][0] >> bc[i][1];
  }
  
  //辺の追加
  for(i=0;i<N;i++){
    //s→R
    add_edge(0,i+1);
    //B→t
    add_edge(i+1+N,2*N+1);
  }
  
  for(i=0;i<N;i++){
    for(k=0;k<N;k++){
      if((rc[i][0]<bc[k][0]) && 
         (rc[i][1]<bc[k][1]) )
        add_edge(i+1,k+1+N);
    }
  }
  
  cout << max_flow(0,2*N+1) << endl;
  return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll m,n; cin >> m >> n;
    ll k = m;
    ll ans = 1LL;
    while (n > 0) {
        ans *= ((n & 1) ? k : 1LL);
        ans %= MOD;
        k = k*k;
        k %= MOD;
        n >>= 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    ll cost=0;
    bool bad=false;
    int i=n-1;
    while(i>=0) {
        if(a[i]>i) bad=true;
        if(i+1<n && a[i]<a[i+1]-1) bad=true;
        cost+=a[i];
        while(i-1>=0 && a[i-1]==a[i]-1) --i;
        --i;
    }
    ll ans=-1;
    if(!bad) ans=cost;
    cout<<ans<<"\n";
}


Measured memory_bytes: 1792
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
if len(C)>=4:
    print("No")
elif len(C)==1:
    if a[0]==0:
        print("Yes")
    else:
        print("No")
elif len(C)==2:
    key=[]
    for k in C.keys():
        key.append(k)
    key.sort()
    if key[0]==0 and C[key[1]] == 2*C[key[0]]:
        print("Yes")
    else:
        print("No")
elif len(C)==3:
    val = []
    key = []
    for k in C.keys():
        key.append(k)
    if key[0] ^ key[1] != key[2]:
        print("No")
        exit()
    for v in C.values():
        val.append(v)
    if val[0]==val[1]==val[2]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14832
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: u64
    };

    if n % 2 == 1 {
        println!("0");
        return;
    }

    let mut res = 0;
    let mut m = 5;
    while m <= n {
        res += n / m / 2;
        m *= 5;
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

#define MX_N 202
#define INF 10000000

#define czek(n,i) ((n&(1<<i))?1:0)
#define rep(j,n) for(int i=j;i<n;i++)
#define revrep(j,n) for(int i=n-1;i>=j;i--)
#define rup(k,n) for(int j=k;j<n;j++)
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef double d;
typedef long double lf;
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<float,float> ff;

int main(){
	int n,h,w;
	cin >> n >> h >> w;
	cout << (n-h+1)*(n-w+1);
	
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

bool check(ll x, ll a, ll b) {
    ll p = a*b;
    ll m = x/2;
    for (ll i = max(1LL, m-10); i<=min(x, m+10); ++i) {
        ll aa = i, bb = x - i + 1;
        if (aa >= a) aa++;
        if (bb >= b) bb++;
        if (aa*bb >= p) return false;
    }
    return true;
}

int main() {
    int Q;
    cin >> Q;
    rep(q, Q) {
        ll a, b;
        cin >> a >> b;
        ll ok = 0, ng = 1e10;
        while (ng-ok>1) {
            ll m = (ok + ng) / 2;
            if (check(m, a, b)) ok = m;
            else ng = m;
        }
        cout << ok << endl;
    }
    return 0;
}


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

int main(void){
  int maxCnt = 0, maxLen = 0;
  string maxCntStr,maxLenStr;
  map<string,int> cnt;
  string s;

  while(cin>>s){
    cnt[s]++;
    if(maxCnt < cnt[s]){
      maxCnt = cnt[s];
      maxCntStr = s;
    }
    if(maxLen < s.length()){
      maxLen = s.length();
      maxLenStr = s;
    }
  }
  cout<<maxCntStr<<" "<<maxLenStr<<endl;

  return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for j in range(m)]

for i in range(n):
    c = 0
    for j in range(m):
        c += A[i][j] * b[j]
    print(c)


Measured memory_bytes: 6012
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();//tyouten
		int m = sc.nextInt();//hen
		List<List<Integer>> path = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			path.add(new ArrayList<Integer>(n));
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			path.get(a).add(b);
			path.get(b).add(a);
		}
		int cnt = 0;
		int bitMax = (int) Math.pow(2, n) - 1;
		Deque<int[]> check = new ArrayDeque<int[]>();
		int[] start = { 1, 0 };//bit,genzaiti-1
		check.addLast(start);
		while (!check.isEmpty()) {
			int[] tmp = check.removeFirst();
			int bit = tmp[0];
			int node = tmp[1];
	//		System.out.println(bit+","+node);
			for (int next : path.get(node)) {
//				System.out.println("next"+next);
//				System.out.println((1 << next) & bit);
				if (((1 << next) & bit) == 0) {
					if (bit + (1 << next) == bitMax) {
						cnt++;
					} else {
						int[] nextnode = { bit + (1 << next), next };
						check.addLast(nextnode);
					}
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21972
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VL as(n+2, 0);
  REP(i,0,n) {
    cin >> as[i+1];
  }
  ll total = 0;
  REP(i,0,n+1) {
    total += abs(as[i+1] - as[i]);
  }
  REP(i,1,n+1) {
    if((as[i-1] <= as[i] && as[i] <= as[i+1]) ||
       (as[i-1] >= as[i] && as[i] >= as[i+1])) {
      cout << total << endl;
    } else {
      ll cost = min(abs(as[i] - as[i-1]), abs(as[i] - as[i+1]));
      cout << total - 2 * cost << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 2048
N = int(input())
A = input()
B = input()
C = input()

res = 0

for i in range(N):
    set_num = len(set([A[i],B[i],C[i]]))
    if set_num == 3:
        res += 2
    elif set_num == 2:
        res += 1

print(res)

Measured memory_bytes: 3060
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);
        var bb = ToIntArray(input.ReadLine(), n);
        var cc = ToIntArray(input.ReadLine(), n);

        Array.Sort(aa);
        Array.Sort(bb);
        Array.Sort(cc);

        long sum = 0;

        for(int i=0; i<n; i++) {
            var b = bb[i];
            long ax = aa.Count() - search(aa, b);
            long cx = search(cc, b+1);
            Debug.WriteLine($"{ax}*{cx}");
            sum += ax * cx;
        }

        return sum;
    }

    //例）二分探索
    //昇順ソートされたlistの数値でx以上の
    //要素のインデクスを返す。
    static int search(int[] list, int x) {
        var st = 0;
        var en = list.Length - 1;
        var p = (st + en) / 2;

        while (true) {
            //終了条件
            if (en - st <= 1) {
                break;
            }

            //探索条件
            if (x > list[p]) {
                st = p;
            } else {
                en = p;
            }
            p = (st + en) / 2;
        }

        //最後の二択および終端の処理
        p = st;
        if (list[p] < x) p = en;
        if (list[p] < x) p++;

        return Math.Max(list.Count() - p, 0);
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 34764
#include <iostream>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
bool is_one_of(char c, string const & s) {
    return s.find(c) != string::npos;
}
bool is_vowel(char c) {
    return is_one_of(c, "aiueo");
}
bool is_voiceless_consonant(char c) {
    return is_one_of(c, "ksthp");
}
int main() {
    while (true) {
        string s; cin >> s;
        if (s == "#") break;
        s = string() + "^^^^" + s + "$$$$$$$$";
        string t;
        bool is_canceled = false;
        repeat (i, s.length()) {
            if (s[i] == '^' or s[i] == '$') {
                continue;
            }
            if (is_canceled and is_vowel(s[i])) {
                t += s[i];
                is_canceled = false;
                continue;
            }
            bool is_left_voiceless_consonant_y = is_voiceless_consonant(s[i - 1]) or (is_voiceless_consonant(s[i - 2]) and s[i - 1] == 'y');
            if (is_left_voiceless_consonant_y and is_one_of(s[i], "iu") and (s[i + 1] == '$' or is_voiceless_consonant(s[i + 1]))) { // rule 1
                t += string() + "(" + s[i] + ")";
                is_canceled = true;
                continue;
            }
            if (is_left_voiceless_consonant_y and is_one_of(s[i], "ao") and is_voiceless_consonant(s[i + 1])) {
                if (s[i + 2] == s[i] or (s[i + 2] == 'y' and s[i + 3] == s[i])) { // rule 2
                    t += string() + "(" + s[i] + ")";
                    is_canceled = true;
                    continue;
                }
            }
            t += s[i];
        }
        cout << t << endl;
    }
    return 0;
}

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

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

  string t;

  for(int i = 0; i < s.size();){

    if(s.substr(i, 6) == "eraser"){
      i += 6;
    }

    else if(s.substr(i, 11) == "dreameraser"){
      i += 11;
    }

    else if(s.substr(i, 10) == "dreamerase"){
      i += 10;
    }

    else if(s.substr(i, 7) == "dreamer"){
      i += 7;
    }

    else if(s.substr(i, 5) == "dream" || s.substr(i, 5) == "erase"){
      i += 5;
    }

    else{
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;

}


Measured memory_bytes: 512
/*
 *  I wish I could travel by the road that crosses baby's mind,
 *  and out beyond all bounds;
 *  Where messengers run errands for no cause
 *  between the kingdoms of kings of no history;
 *  Where Reason makes kites of her laws and flies them,
 *  and Truth sets Fact free from its fetters.
 *                                           Rabindranath Tagore
 */

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

#ifndef ORZ_EVERYBODY_BUT_ME
#define ORZ_EVERYBODY_BUT_ME
#endif

#ifndef SOCIALISM
#define SOCIALISM
#endif

unsigned long long operator "" _love(unsigned long long literal) {
    return literal;
}

typedef long long ll;

double count(ll x) {
    double res = 0;
    for (; x > 0; x /= 10) res += x % 10;
    return res;
}

int main() {
    int k;
    scanf("%d", &k);
    ll cur = 1, add = 1;
    for (int i = 0; i < k; ++i) {
        cout << cur << '\n';
        cur += add;
        if (cur / count(cur) > (cur + add) / count(cur + add)) {
            cur -= add;
            cur += (add *= 10);
        }
    }
    return 0;
}


Measured memory_bytes: 256
def main():
	N = int(input())
	s = {}
	pair = 0
	for _ in range(N):
		b = "".join(sorted([a for a in input()]))
		if b in s.keys():
			pair += s[b]
			s[b] += 1
		else:
			s[b] = 1
	print(pair)
main()

Measured memory_bytes: 17852