akhauriyash/Code-Regression huggingface dataset:
eval"_,*A="+gets.split*?,
s=*$<
f=->i{s[i]&.chop&.bytes{|x|A[y=s[i].sum-x-75]+=1;$*[i]=""<<y+65;f[i+1]if~0<A[x-=65]-=1;A[x]+=1;A[y]-=1}||puts(:Yes,$*)+exit}
f[0]
puts:No

Measured memory_bytes: 155176
import java.util.Scanner;


// 147_b
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        out(Math.min(b / a, c));
    }

    /*
     * 以下メソッド集
     */

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

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

    static int gcd(int a, int b) {

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

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <numeric> //lcm

#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1 << 29; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int &a, int b) { if (a < b) {a = b; return true;} else return false;}


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

  int n, k;
	cin >> n >> k;

	vector<ll> m(n);
	rep(i,n) cin >> m[i];
	sort(m.begin(), m.end(), greater<ll>());

	ll ans =0;
	for(int i = k; i < n; ++i) ans += m[i];

	cout << ans << endl;
}




Measured memory_bytes: 1792
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

long long calc_simple(long long aI, long long aO, long long aJ, long long aL) {
    return aO * 2 + (aI / 2) * 4 + (aJ / 2) * 4 + (aL / 2) * 4;
}

int main(int argc, char **argv) {
    long long aI, aO, aT, aJ, aL, aS, aZ;
    std::cin >> aI >> aO >> aT >> aJ >> aL >> aS >> aZ;

    long long three_min = std::min(std::min(aJ, aL), aI);

    long long ret = 0;
    if (three_min == 0) {
        std::cout << calc_simple(aI, aO, aJ, aL) / 2 << std::endl;
        return 0;
    }

    long long tmp1 = three_min * 6 + calc_simple(aI - three_min, aO, aJ - three_min, aL - three_min);
    long long tmp2 = (three_min - 1) * 6 + calc_simple(aI - three_min + 1, aO, aJ - three_min + 1, aL - three_min + 1);

    std::cout << std::max(tmp1, tmp2) / 2 << std::endl;

    return 0;
}


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

int main() {
	int n,t_point,h_point;
	cin >> n;
	string a[n][2];
	t_point = 0;
	h_point = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i][0] >> a[i][1];
	}
	for(int i = 0; i < n; i++){
		if(a[i][0] > a[i][1]){
			t_point += 3;
		}else if(a[i][0] < a[i][1]){
			h_point += 3;
		}else{
			t_point++;
			h_point++;
		}
	}
	cout << t_point << " " << h_point << endl;
	return 0;
}



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

int n;
ll a[300010];

int main() {
	while(scanf("%d", &n)!=EOF){
        for(int i=0; i<3*n; i++) scanf("%lld", &a[i]);
        sort(a, a+3*n);
        ll sum=0;
        for(int i=0; i<n; i++){
            sum += a[3*n-2-2*i];
        }
        printf("%lld\n", sum);
	}
	return 0;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int x = 0;
    int ans = -1;
    for(int i=0; i<k; ++i){
        x *= 10;
        x += 7;
        x %= k;
        if(x == 0){
            ans = i + 1;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
a, b, c, x, y = map(int, input().split())
n = max(x, y)
ans = float('inf')
for i in range(n + 1):
    buyab = i * c * 2
    buya = max((x - i), 0) * a
    buyb = max((y - i), 0) * b
    sum = buyab + buya + buyb
    ans = min(ans, sum)
print(ans)

Measured memory_bytes: 39408
ipt = gets.chomp!.split(' ').map(&:to_i)
min, _, _, max = ipt.sort
sync = 0
a_push = false
b_push = false
min.upto(max) do |time|
  a_push = true if time == ipt[0] && !a_push
  a_push = false if time == ipt[1] && a_push
  b_push = true if time == ipt[2] && !b_push
  b_push = false if time == ipt[3] && b_push
  sync += 1 if a_push && b_push
end
puts sync

Measured memory_bytes: 1788
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        ll l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
arr = list(map(int, input().split()))
count = 0
gokei = 0
mi = float('inf')
flg = False
for i in arr:
    gokei += abs(i)
    mi = min(mi,abs(i))
    if i < 0:
        count += 1
    if i == 0:
        flg = True
if flg or count % 2 == 0:
    print(gokei)
else:
    print(gokei-mi*2)

Measured memory_bytes: 14284
import collections
class Dinic:
    def __init__(self, n):
        self.n = n
        self.g = [[] for i in xrange(n)]
    def add_edge(self, fr, to, cap):
        self.g[fr].append([to, cap, len(self.g[to])])
        self.g[to].append([fr, 0, len(self.g[fr])-1])
    def add_multi_edge(self, v1, v2, cap1, cap2):
        self.g[v1].append([v2, cap1, len(self.g[v2])])
        self.g[v2].append([v1, cap2, len(self.g[v1])-1])
    def bfs(self, s):
        level = [-1]*self.n
        deq = collections.deque()
        level[s] = 0
        deq.append(s)
        while deq:
            v = deq.popleft()
            for e in self.g[v]:
                if e[1]>0 and level[e[0]]<0:
                    level[e[0]] = level[v] + 1
                    deq.append(e[0])
        self.level = level
    def dfs(self, v, t, f):
        if v==t: return f
        es = self.g[v]
        level = self.level
        for i in xrange(self.it[v], len(self.g[v])):
            e = es[i]
            if e[1]>0 and level[v]<level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d>0:
                    e[1] -= d
                    self.g[e[0]][e[2]][1] += d
                    self.it[v] = i
                    return d
        self.it[v] = len(self.g[v])
        return 0
    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t]<0: break
            self.it = [0]*self.n
            while True:
                f = self.dfs(s, t, 10**9+7)
                if f>0:
                    flow += f
                else:
                    break
        return flow
h, w = map(int, raw_input().split())
A = [raw_input() for i in xrange(h)]
dinic = Dinic(h+w+2)
start = h+w; end = h+w+1
INF = 10**9+7
for i in xrange(h):
    for j in xrange(w):
        c = A[i][j]
        if c is 'o':
            dinic.add_multi_edge(i, h + j, 1, 1)
        elif c is 'S':
            dinic.add_edge(start, i, INF)
            dinic.add_edge(start, h + j, INF)
        elif c is 'T':
            dinic.add_edge(i, end, INF)
            dinic.add_edge(h + j, end, INF)
ans = dinic.max_flow(start, end)
if ans >= INF:
    print -1
else:
    print ans


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

using namespace std;

typedef struct{
  int begin;
  int end;
  bool f;
}fint;
fint T[101];

int times = 1;
int n;
int graph[101][101];

void bfs(int now){

  T[now].f = true;
  T[now].begin = times++;

  for( int i = 1 ; i <= n; i++ ){
    if( graph[now][i] == 1 && !T[i].f ) bfs(i);
  }
  T[now].end = times++;

}

int main(void){

  int s,t,u;
  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
    cin >> s >> t;
    for( int j = 1 ; j <= t ; j++ ){
      cin >> u;
      graph[s][u] = 1;
    }
  }
  for( int i = 1 ; i <= n ; i++ ){
    T[i].begin = 0;
    T[i].end = 0;
    T[i].f = false;
  }
  for( int i = 1 ; i <= n ; i++ ){
    if( !T[i].f ) bfs(i);
  }

  for( int i = 1 ; i <= n ; i++ ){
    cout << i << " " << T[i].begin << " " << T[i].end << endl;
  }


  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;



int main(){

	int a, b;
	cin >> a >> b;
	cout << a+b/2 << endl;

	return 0;
}


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

int a[31][100001];

signed main(){

  int N,C; cin >> N >> C;
  for(int i = 0; i < N; i++){
    int s,t,c; cin >> s >> t >> c;
    a[c][s-1]++; a[c][t]--;
  }

  for(int i = 0; i < 30; i++){
    for(int j = 0; j < 100000; j++){
      a[i+1][j+1] = a[i+1][j+1] + a[i+1][j];
    }
  }

  int ans = 1;
  for(int i = 0; i < 100000; i++){
    int cnt = 0;
    for(int j = 0; j < 30; j++){
      if(a[j+1][i] == 1) cnt++;
    }
    ans = max(ans,cnt);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main()
{
    string s;
    cin>>s;
    int flag=0;
    for(int i=0;s[i]!='\0';i++)
    {
        if(s[i]=='7')
            flag=1;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  vector<int>data(3);
  data.at(0)=A;
  data.at(1)=B;
  data.at(2)=C;
  sort(data.begin(),data.end());
  if((data.at(0)+data.at(1))%2!=0){
    cout << ((data.at(2)+1)*2-data.at(1)-data.at(0)+1)/2 << endl;
  }
  else{
    cout << (data.at(2)*2-data.at(1)-data.at(0))/2 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int loop1,loop2;
    int how_q;
    scanf("%d",&how_q);
    int how_time[how_q];
    for(loop1=0;loop1<how_q;loop1++){
        scanf("%d",&how_time[loop1]);
    }
    int how_drink;
    scanf("%d",&how_drink);
    int drink_data[how_drink][2];
    int output;
    for(loop1=0;loop1<how_drink;loop1++){
        scanf("%d%d",&drink_data[loop1][0],&drink_data[loop1][1]);
        output=0;
        for(loop2=0;loop2<how_q;loop2++){
            if(drink_data[loop1][0]-1==loop2){
                output+=drink_data[loop1][1];
            }else{
                output+=how_time[loop2];
            }
        }
        printf("%d\n",output);
        output=0;
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    ll X;
    cin >> X;

    ll a = X/500;
    X -= a*500;
    ll b = X/5;
    cout << a*1000 + b*5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int N;
  cin >> N;
  int count = 0;
  for(int i = 1;i <= N;i++){
    if(1 <= i && i <= 9){
      count++;
    }else if(100 <= i && i <= 999){
      count++;
    }else if(10000 <= i && i <= 99999){
      count++;
    }
  }
  cout << count << endl;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

long long gcd(long long a, long long b) {
    if (a < b) std::swap(a, b);
    if (b == 0) return a;

    while (b > 0) {
        long long tmp = b;
        b = a%b;
        a = tmp;
    }
    return a;
}

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];

    ll g = A[0];
    for (int i=1; i<N; ++i) g = ::gcd(g, A[i]);
    if (g > 1) {
        cout << "not coprime" << '\n';
        return;
    }

    set<ll> st;
    for (ll x : A) {
        for (ll i=2; i*i<=x; ++i) {
            if (x%i == 0) {
                if (st.count(i)) {
                    cout << "setwise coprime" << '\n';
                    return;
                }
                st.insert(i);
                while (x%i == 0) x /= i;
            }
        }
        if (x > 1) {
            if (st.count(x)) {
                cout << "setwise coprime" << '\n';
                return;
            }
            st.insert(x);
        }
    }
    cout << "pairwise coprime" << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 11104
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)

int main(void) {
	string s;
	cin >> s;
	for (int i = 0;i < s.length();i++) {
		if (s[i] == '1')cout << 9;
		else cout << 1;
	}
	cout << endl;
	return 0;

}

Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int n;
    string s[2];

    cin >> n;
    cin >> s[0] >> s[1];

    ll ans;
    int pos, prev;
    if ( s[0][0] == s[1][0] ) {
        ans = 3;
        prev = 1;
        pos = 1;
    } else {
        ans = 6;
        prev = 2;
        pos = 2;
    }
    while( pos < n ) {
        if ( s[0][pos] == s[1][pos] ) {
            ans = (prev == 1 ? (ans * 2)%MOD : (ans * 1)%MOD);
            prev = 1;
            ++pos;
        } else {
            ans = (prev == 1 ? (ans * 2)%MOD : (ans * 3)%MOD);
            prev = 2;
            pos += 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    int ans = 0;
    if(a%2 == 0 && a == b && b == c){
        cout << -1 << endl;
        return 0;

    }
    while(1){
        if(a%2 == 0 && b % 2 == 0 && c % 2 == 0){
            ll x = a,y = b,z=c;
            a = y/2+z/2;
            b = x/2+z/2; 
            c = y/2+x/2;
            ans++;
            //cout << a << b << c << endl;
        }else break;
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 1000000 + 5;

int n, cnt;
int a[N];

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	for (int i = 1; i <= n; i++) if (a[i] & 1) cnt++;
	if ((cnt & 1) == 0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll a[1100000];
map<ll,ll> x;
int main(){
    ll n;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    bool pc=true;
    bool sc=false;
    rep(i,0,n){
        ll p=a[i];
        ll cnt=2;
        while(cnt*cnt<=p){
            if(p%cnt==0){
                while(p%cnt==0){
                    p/=cnt;
                }
                x[cnt]++;
                if(x[cnt]>1)pc=false;
            }
            else cnt++;
        }
        if(p>1)x[p]++;
        if(x[p]>1)pc=false;
        if(!pc)break;
    }
    if(!pc){
        ll q=a[0];
        rep(i,1,n)q=gcd(q,a[i]);
        if(q==1)sc=true;
    }
    if(pc)cout<<"pairwise coprime";
    else if(sc)cout<<"setwise coprime";
    else cout<<"not coprime";
}




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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define debug(x) cout << #x << ":" << x << endl;
#define debug2(x) for(auto a : x) cout << a << " "; cout << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

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

class UnionFind {
public:
    vector<int> par, sizes;

    UnionFind(int n) : par(n), sizes(n, 1) {
        rep(i, n) par[i] = i;
    }

    int root(int x) {
        if (x == par[x]) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return sizes[root(x)];
    }
};

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

    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<int> can_lang[m], p[n];

    rep(i, n) {
        int k;
        cin >> k;

        rep(j, k) {
            int l;
            cin >> l;
            l--;
            can_lang[l].push_back(i);
            p[i].push_back(l);
        }
    }

    rep(l, m) rep(i, (int) (can_lang[l].size()) - 1) {
        uf.unite(can_lang[l][i], can_lang[l][i + 1]);
    }

    rep(pi, n) rep(i, (int) (p[pi].size()) - 1) {
        int la = p[pi][i], lb = p[pi][i + 1];
        if (can_lang[la].size() == 0 || can_lang[lb].size() == 0) continue;
        uf.unite(can_lang[la][0], can_lang[lb][0]);
    }
    YES(uf.size(0) == n);
    return 0;
}



Measured memory_bytes: 9208
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

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

	int ans = 0;

	while(N > 0) {
		N /= K;
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n; cin >> n;
    int c1 = 0, c2 = 0, c3 = 0;
    V<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) c1++;
        if (a[i] == 2) c2++;
        if (a[i] == 3) c3++;
    }

    V< V< V<double> > > dp(c1 + c2 + c3 + 1, V< V<double> >(c2 + c3 + 1, V<double>(c3 + 1, -1)));
    auto memo = [&](auto && self, int r1, int r2, int r3) -> double {
        if (r1 == 0 && r2 == 0 && r3 == 0) return dp[r1][r2][r3] = 0;
        if (dp[r1][r2][r3] >= 0) return dp[r1][r2][r3];

        double sum = n;
        if (r1 > 0) sum += double(r1) * self(self, r1 - 1, r2, r3);
        if (r2 > 0) sum += double(r2) * self(self, r1 + 1, r2 - 1, r3);
        if (r3 > 0) sum += double(r3) * self(self, r1, r2 + 1, r3 - 1);
        return dp[r1][r2][r3] = sum / double(r1 + r2 + r3);
    };
    cout << memo(memo, c1, c2, c3) << '\n';
    return 0;
}


Measured memory_bytes: 219876
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int k;
  cin >> k;
  double ans = 100.0;
  for(int i=0; i<4000; i++){
    ans *= 1.01;
    long long int tmp = floor(ans);
    if(tmp>=k){
      cout << i+1 << endl;
      return 0;
    }
    ans = tmp;
  }
  return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

const int MAX_N = 1<<18;

int N = 1<<16;
int seg1[MAX_N * 2 - 1];

void init1() {
    for (int i = 1; i <= 2 * N - 1; i++) {
        seg1[i] = INT_MAX;
    }
}

// i は 0-indexed
void update1(int i, int x) {
    i += N; 
    seg1[i] = x;
    while (i > 1) {
        i /= 2;
        seg1[i] = min(seg1[i * 2], seg1[i * 2 + 1]);
    }
}

int query1(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return seg1[k];
    else {
        int vl = query1(a, b, k * 2, l, (l + r) / 2);
        int vr = query1(a, b, k * 2 + 1, (l + r) / 2, r);
        return min(vl, vr);
    }
}

int seg2[MAX_N * 2 - 1];

void init2() {
    for (int i = 1; i <= 2 * N - 1; i++) {
        seg2[i] = 0;
    }
}

// i は 0-indexed
void update2(int i, int x) {
    i += N; 
    seg2[i] = x;
    while (i > 1) {
        i /= 2;
        seg2[i] = max(seg2[i * 2], seg2[i * 2 + 1]);
    }
}

int query2(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return seg2[k];
    else {
        int vl = query2(a, b, k * 2, l, (l + r) / 2);
        int vr = query2(a, b, k * 2 + 1, (l + r) / 2, r);
        return max(vl, vr);
    }
}

int main() {
    init1();
    init2();
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        update1(i, a[i]);
        update2(i, a[i]);
    }
    if (n == k) {
        dump(1);
        return 0;
    }
    Int res = 0;
    Int cnt = 1;
    vector<bool> v(n, false);
    Int call = 0;
    for (Int i = n - 1; i > 0; i--) {
        if (a[i] > a[i - 1]) {
            cnt++;
        }
        else {
            cnt = 1;
        }
        if (cnt >= k) {
            v[i - 1] = true;
            call++;
        }
    }
    set<Int> st;
    for (Int i = 0; i < k; i++) {
        st.insert(a[i]);
    }
    for (Int i = k; i < n; i++) {
        st.insert(a[i]);
        if (v[i - k]) {
            st.erase(a[i - k]);
            if (!v[i - k + 1]) {
                res++;
            }
            continue;
        }
        if (res == 0) {
            res = 1;
        }
        if (v[i - k + 1]) {
            st.erase(a[i - k]);
            continue;
        }
        if (a[i - k] == *st.begin() && a[i] == *st.rbegin()) {
            st.erase(a[i - k]);
            continue;
        }
        res++;
        //cout << i - k << " " << res << endl;
        st.erase(a[i - k]);
    }
    // for (Int i = 0; i < n - k; i++) {
    //     if (v[i]) {
    //         continue;
    //     }
    //     if (i < n - k && a[i] == query1(i, i + k + 1, 1, 0, N) && a[i + k] == query2(i, i + k + 1, 1, 0, N)) {
    //         continue;
    //     }
    //     res++;
    // }   
    dump(res + (call >= 1 ? 1 : 0));
    return 0;
}

Measured memory_bytes: 14208
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
using namespace std;
using ll = long long;

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

	if (D == 25)
		cout << "Christmas\n";
	else if (D == 24)
		cout << "Christmas Eve\n";
	else if (D == 23)
		cout << "Christmas Eve Eve\n";
	else
		cout << "Christmas Eve Eve Eve\n";
}

Measured memory_bytes: 256
N = int(input())
if N < 105:
    print(0)
else:
    ans = 0
    for n in range(105,N+1,2):
        count = 0
        for i in range(1,n+1):
            if n % i == 0:
                count += 1
        if count == 8:
            ans += 1
    print(ans)


Measured memory_bytes: 2940
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	
    	Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		
		if(a.charAt(0) == 'H'){   
		    if(b.charAt(0) == 'H'){
		        System.out.println('H');
		    }
		    else{
		        System.out.println('D');
		    }
		}
		else{
		    if(b.charAt(0) == 'H'){
		        System.out.println('D');
		    }
		    else{
		        System.out.println('H');
		    }
		}
	}
 
}

Measured memory_bytes: 21204
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int  r, c, d ; 
map <int,pii> m;

signed main()
{
    cin >> r >> c >> d ; 
    vi res(r*c+5);
    for (int i=0;i<r;i++) {
    	for (int j=0,in;j<c;j++){
    		cin >> in ; 
    		pii a; a.ff=i,a.ss=j ; 
    		m[in] = a ; 
    	}
    }
    for (int i=d;i <= r*c;i++){ 
    	res[i] = res[i-d] + abs(m[i].ff-m[i-d].ff) + abs(m[i].ss-m[i-d].ss) ; 
    	//cout << res[i] << " ";
    } 
    //cout << endl;
    int q; cin >> q; 
	while (q--){
		int l,r; cin >> l >> r ; 
		cout << (res[r]-res[l]) << endl ; 
	}
    return 0;
}


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

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

    string ans = "No";
    for(int i=0;i<3;i++){
        if(s[i]-'0' == 7){
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>

using namespace std;

#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque



#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>

#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>

#define vi vector<ll>
#define vs vector<string>

#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator


#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second
#define pi 2*acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT_ count()
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT_ getline
#define NL_   "\n"

#define for(i, n) for(i = 0; i < n; i++)
#define fe(i, n) for(i = 1; i <= n; i++)

#define ul unsigned long long int
#define ll long long int
#define  MAX 250000

ll N, T, tC = 0, i, j, k;



ul abs(ul a, ul b)
{
    if(a > b)
        return a-b;
    else
        return b - a;
}



int main()
{
    FAST;

//    cin >> N;
//    ll m;
//    cin >> m;
//    double arr[N+1];
//    double sum = 0;
//    for(i,N)
//    {
//        cin >> arr[i];
//        sum += arr[i];
//    }
//
//    sum = (sum)/(4.00*(double)m);
//    ll t = 0;
//    for(i, N)
//    {
//        if(arr[i]>= sum)
//            t++;
//    }
//    if(t>=m)
//        cout <<"Yes";
//    else
//        cout <<"No";



    ul n, k;
    cin >> n >> k;
    if(n > k )
    {
        n  = n %k;
    }
    if(n <=k)
    {
        if(n <=abs(n,k))
        {
            cout << n;
        }
        else
            cout << abs(n,k);
    }


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define loop(i,j,n) for(i=j;i<n;i++)
#define rloop(i,j,n) for(i=n;i>=j;i--)
#define INF 2147483647
#define ll long long
#define pii pair<int,int>
#define eps 1e-9
#define mii map<int,int>
#define vi vector<int>
#define all(n) n.begin(),n.end()
#define inf INF
#define INFLL 9223372036854775807
using namespace std;
int main()
{
    int n,m,cnt=0,i,j,k,tc,t;
    int a,b;
    cin>>n;
    cin>>a>>b;
    if(n==2)cout<<"Borys\n";
    else
    {
        if(abs(a-b-1)%2==0)cout<<"Borys\n";
        else cout<<"Alice\n";
    }

}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    ll n;cin>>n;
    ll min=inf;

    for(ll i=1;i*i<=n;i++){
        if(n%i==0&&min>n/i+i-2){
                min=n/i+i-2;
        }
    }

    cout<<min<<endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python

get_y = lambda a,b,c,d,e,f: (f-(c*d/a)) / (e-(b*d/a))
get_x = lambda a,b,c,y: (c-b*y)/a

if __name__ == "__main__":
    while True:
        try:
            a,b,c,d,e,f = [float(z) for z in raw_input().split()]
            y = get_y(a,b,c,d,e,f)
            x = get_x(a,b,c,y)
            print "%.3f %.3f" % (x, y)
        except EOFError:
            break

Measured memory_bytes: 4236
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  lll a,b,c,d;

  cin >> a >> b >> c >> d;
  
  lll maxc[5];

  //if(a>=0 && c >= 0){
  //  max = b * d;
  //}
  //else if(b < 0 && d < 0){
  //  max = a * c;
  //}
  //else if(b < 0 && c >= 0){
  //  max = b * c;
  //}
  //else if(a >= 0 && d < 0){
  //  max = a * d;
  //}
  //else if(

  maxc[0] = a * c;
  maxc[1] = a * d;
  maxc[2] = b * c;
  maxc[3] = b * d;

  maxc[4] = -1e18;
  if( (a<=0 && 0<=b) ||
      (c<=0 && 0<=d)){
    maxc[4] = 0;
  }

  lll max;

  max = -1e18;

  for(ii=0;ii<5;ii++){

    if(max < maxc[ii]){
      max = maxc[ii];
    }
    //cout << "ii:" << ii << max << endl;
  }
  //max = -2000;  
  cout << max << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll f=0,re=0;
  rep(i,n){
    re+=(a[i]+f)/2;
    f=(a[i]+f)%2;
    if(!a[i]) f=0;
  }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 1024
// 安定なソート p.72
// 今回は答えをみた（構造体が分からん）

#include <iostream>
using namespace std;

struct Card {char suit, value; };

void bubble(struct Card A[], int N) {
    for (int i=0; i<N; i++) {
        for (int j=N-1; j>=i; j--) {
            if (A[j].value < A[j-1].value) {
                Card t = A[j];
                A[j] = A[j-1];
                A[j-1] = t;
            }
        }
    }
}


void selection(struct Card A[], int N) {
    for (int i=0; i<N; i++) {
        int minj = i;
        for (int j = i; j<N; j++) {
            if (A[j].value < A[minj].value) minj = j;
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}


void print(struct Card A[], int N) {
    for (int i=0; i<N; i++) {
        if (i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}
// バブルソートと選択ソートの結果を比較
bool isStable(struct Card C1[], struct Card C2[], int N) {
    for (int i = 0; i < N; i++) {
        if (C1[i].suit != C2[i].suit )
            return false;
    }
    return true;
}


int main()
{
    Card C1[100], C2[100];
    int N;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> C1[i].suit >> C1[i].value;
        //cout << "i: " << i << ", suit: " << C1[i].suit << ", value: " << C1[i].value << endl;
    }

    for (int i = 0; i < N; i++) C2[i] = C1[i];

    bubble(C1, N);
    selection(C2, N);

    print(C1, N);
    cout << "Stable" << endl;

    print(C2, N);
    if (isStable(C1, C2, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    return 0;
}


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

#ifndef _WIN32
    #define getchar getchar_unlocked
#endif

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
//#define int LLI
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define F1(i,n) FOR(i,1,n)

typedef long long LLI;
typedef unsigned long long LLU;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LLI, LLI> pll;
typedef vector<int> vi;

#ifdef ONLINE_JUDGE
ostream cnull(NULL);
#define cerr cnull
#endif

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr<<*sdbg++;
  cerr<<"="<<h<<",";
  _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define dbgV(R) {cerr << #R << "=["; for(int e : R) cerr << e << ", "; cerr << "E]\n";}
#define dbgA(R, n) {cerr << #R << "=["; for(int i = 0; i <= n; ++i) cerr << R[i] << ", "; cerr << "E]\n";}
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

vector<tuple<int, int, int> > edges;
int K;

int32_t main()
{
    boost;
    int L; cin >> L;
	while(1<<(K+1) <= L) ++K;
	for(int i = 1; i <= K; ++i) {edges.PB(make_tuple(i, i + 1, 0)); edges.PB(make_tuple(i, i + 1, 1<<(i - 1)));}
	int pom = 1<<K;
	for(int i = K - 1; i >= 0; --i) if(L & (1<<i)) {edges.PB(make_tuple(i + 1, K + 1, pom)); pom += 1<<i;}
	cout << K + 1 << " " << SZ(edges) << '\n';
	for(auto e : edges) cout << get<0>(e) << " " << get<1>(e) << " " << get<2>(e) << '\n';
}



Measured memory_bytes: 256
def check(pat):
    for i in range(W - 2):
        mask = 0b11 << i
        if pat & mask == mask:
            return False
    return True


def simulate(a1, pat):
    if a1 != W - 1 and pat & 1 << a1 != 0:
        return a1 + 1
    elif a1 != 0 and pat & 1 << a1 - 1 != 0:
        return a1 - 1
    else:
        return a1


H, W, K = map(int, input().split())
dp = [[0] * W for h in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
    for pat in range(2 ** (W - 1)):
        for w in range(W):
            if check(pat):
                dp[h][simulate(w, pat)] += dp[h - 1][w]
                dp[h][simulate(w, pat)] %= 1000000007
print(dp[H][K - 1])


Measured memory_bytes: 3064
from collections import deque


n, u, v = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n - 1)]

tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = info[i]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

v -= 1
u -= 1

root = u
visited = [False] * n
q = deque([root])
visited[root] = True
new_tree = [[] for i in range(n)]

while q:
    pos = q.pop()
    for next_pos in tree[pos]:
        if visited[next_pos]:
            continue
        visited[next_pos] = True
        if next_pos != v:
            q.append(next_pos)
        new_tree[pos].append(next_pos)
        new_tree[next_pos].append(pos)

is_leaf = [False] * n
for i in range(n):
    if len(new_tree[i]) == 1:
        is_leaf[i] = True
        
time = [-1] * n
root = v
time[root] = 0
q = deque([root])
while q:
    pos = q.pop()
    for next_pos in new_tree[pos]:
        if time[next_pos] >= 0:
            continue
        time[next_pos] = time[pos] + 1
        q.append(next_pos)
#print(time)

time2 = [-1] * n
root = u
time2[root] = 0
q = deque([root])
while q:
    pos = q.pop()
    for next_pos in new_tree[pos]:
        if time2[next_pos] >= 0:
            continue
        time2[next_pos] = time2[pos] + 1
        q.append(next_pos)
#print(is_leaf)
#print(time)
#print(time2)
can_reach = [False] * n
for i in range(n):
    if time[i] > time2[i] and is_leaf[i]:
        can_reach[i] = True
    
ans = 0
for i in range(n):
    if can_reach[i]:
        ans = max(ans, time[i] - 1)
print(ans)

Measured memory_bytes: 93144
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int n, x;
  readf("%s %s\n", &n, &x);
  auto a = readln.chomp.split.to!(int[]);
  sort(a);
  int cnt;
  foreach (i; 0..n) {
    if (i == n - 1 && a[i] != x) {
      break;
    } else if (a[i] <= x) {
      cnt++;
      x -= a[i];
    } else {
      break;
    }
  }
  cnt.writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//ll mod = 1000000007;
ll mod = 998244353;
vector<int> g[200010];
int n, root = 0;

vector<int> ans(200010);

void dfs(int v, int p)
{

    rep(i, g[v].size())
    {
        if (g[v][i] == p)
        {
            continue;
        }
        ans[g[v][i]] += ans[v];
        dfs(g[v][i], v);
    }
}

signed main()
{
    int q;
    cin >> n >> q;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i, q)
    {
        int p, x;
        cin >> p >> x;
        ans[p] += x;
    }
    dfs(1, -1);
    rep(i, n)
    {
        cout << ans[i + 1] << ((i == n - 1) ? "\n"s : " "s);
    }
    return 0;
}

Measured memory_bytes: 24380
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>
#include<map>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
typedef pair<ll,ll> LL_LLP;
#define INF 1000000007
#define MAX_H 20000

#define ARRAY_MAX 100005

typedef struct union_find{
    
    int pa[ARRAY_MAX];
    int ra[ARRAY_MAX];  
    //vector<int> pa(ARRAY_MAX);//親
    //vector<int> ra(ARRAY_MAX);//木の深さ
    //n要素で初期化
    void init(int n){
        for(int i = 0;i < n;i++){
            pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
            ra[i] = 0;/*各ノード自体の高さは0*/
        }
    }
    //木の根を求める
    int find(int x){
        if(pa[x] == x){
            return x;/*根ならそのノードの番号を返す*/
        }else{
            return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
        }
    }

    //xとyの属する集合を併合する
    void unite(int x,int y){
        x = find(x);//xの根の番号を探す
        y = find(y);//yの根の番号を探す
        if(x == y){//一致すればつながっている
            return;
        }
        if(ra[x] < ra[y]){//xの高さが低いなら高いほうにつなぐ、そして高さは大きい方(y)になる
            pa[x] = y;
        }else{
            pa[y] = x;//yの高さが低いなら高いほうにつなぐ、そして高さは大きいほう(x)になる
            if(ra[x] == ra[y]){//高さが一致しているなら併合の高さは1増える
                ra[x]++;
            }
        }
    }

    //xとyが同じ集合に属するか判定
    bool same(int x,int y){
        return find(x) == find(y);//同じ集合なら1、違うなら0が返る
    }
}UF;

UF num;

int main(){

    int n,m;
    cin >> n >> m;
    vector<int> arr(n);
    REP(i,n){
        cin >> arr[i];
        arr[i]--;
    }
    //acout << n-1 << endl;
    num.init(n);

    /*REP(i,n){
        cout << num.pa[i] << " ";
    }
    cout << endl;*/

    REP(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;//配列の添え字に合わせる
        num.unite(a,b);
    }

    /*REP(i,n){
        cout << num.pa[i] << " ";
    }
    cout << endl;
    */

    int ans = 0;
    REP(i,n){

        if(num.same(i,arr[i])){
            ans++;
        }
        //cout << i << ans << endl;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1408