akhauriyash/Code-Regression huggingface dataset:
import math


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n = int(input())
a = factorization(n)
if a[0][0] == 1:
    print(0)
else:
    b = []
    c = [0,1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190]
    for i in range(len(a)):
        b.append(a[i][1])
    ans = 0
    for i in range(len(b)):
        for j in range(len(c)):
            if b[i] == c[j]:
                ans +=j
                break
            elif b[i] < c[j]:
                ans += j-1
                break
                
    print(ans)

Measured memory_bytes: 9540
#include<iostream>
using namespace std;
int main(void){
	int data[100002];
	int n=0;
	cin>>n;
	for(int i=0;i<=100001;i++)data[i]=0;
	for(int i=0;i<n;i++){
		int a=0;
		cin>>a;
		data[a]++;
	}
	int max=0;
	for(int i=1;i<=100000;i++){
		int a=data[i-1]+data[i]+data[i+1];
		if(max<a)max=a;
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;



int main(void){
	int k, n; cin >> k >> n;
	ll max_dist = 0;
	vint a(n);
	ll ans = 0;
	rep(i, n){
		cin >> a[i];
		if(i == 0) continue;
		max_dist = max(max_dist, abs(a[i-1]-a[i]));
	}
	max_dist = max(max_dist, a[0]+abs(k-a[n-1]));
	ans = k - max_dist;


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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define MAX 100
class State {
public:
	int p, b, cost;
	State(int p = 0, int b = 0, int cost = 0) :
			p(p), b(b), cost(cost) {
	}
};
int n, B[MAX][2];
int bfs() {
	bool V[MAX][2];
	queue<State> Q;
	rep(i, n)
		rep(j, 2)
			V[i][j] = false;
	int s0 = 0, s1 = 0;
	if (B[s0][0] == 1)
		while (s0 + 1 < n && B[s0 + 1][0] == 1)
			s0++;
	if (B[s1][1] == 1)
		while (s1 + 1 < n && B[s1 + 1][1] == 1)
			s1++;
	V[s0][0] = V[s1][1] = true;
	Q.push(State(s0, 0, 0));
	Q.push(State(s1, 1, 0));
	State u, v;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		if (u.p == n - 1)
			return u.cost;
		for (int r = 0; r < 3; r++) {
			int np = u.p + r;
			int nb = (u.b + 1) % 2;
			if (np >= n)
				continue;
			if (B[np][nb] == 2)
				while (B[np][nb] == 2)
					np--;
			if (B[np][nb] == 1)
				while (np + 1 < n && B[np + 1][nb] == 1)
					np++;
			if (V[np][nb])
				continue;
			V[np][nb] = true;
			Q.push(State(np, nb, u.cost + 1));
		}
	}
	return -1;
}
main() {
	while( cin >> n ) {
		if ( n == 0 ) break;
		rep(i, n) cin >> B[i][0];
		rep(i, n) cin >> B[i][1];
		int cost = bfs();
		if ( cost < 0 ) cout << "NA" << endl;
		else cout << cost << endl;
	}
}

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

int main(void){
  char s[1010];
  if(scanf("%s",s) == EOF) return 1;
  if(s[strlen(s)-1]=='s') strcat(s,"e");
  strcat(s,"s");
  printf("%s\n",s);
  return 0;
}

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

int main(){
	// sengen
	LL n;
	// nyuryoku
	cin >> n;
	LL ans = 0;
	// keisan
	for(LL i=1;i<=n;i++){
		LL wari = n/i;
		ans += i*wari*(wari + 1)/2;
	}
	// syutsuryoku
	cout << ans;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(void)
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans = h[0];
    rep(i,n-1){
        if (h[i] < h[i+1]){
            ans += h[i+1] - h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N){
        cin >> A[i];
        A[i]--;
        B[A[i]] = i;
    }
    set<ll> st;
    ll ans = 0;
    rep(i,N){
        ll x = B[i];
        ll l = -1,r = N;
        st.insert(x);
        auto itr = st.find(x);
        if(itr != st.begin()){
            itr--;
            l = *itr;
            itr++;
        }
        itr++;
        if(itr != st.end()){
            r = *itr;
        }
        ans += (i+1) * (r - x) * (x - l);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

#define MAX_N 100010

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

    int n, m;
    cin >> n >> m;
    bool vis[MAX_N];
    rep(i, n) vis[i] = false;
    vector<int> G[MAX_N];
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vis[0] = true;
    vector<int> nxt(n, -1);
    int l = 0, r = 0, len = 1;
    while (1)
    {
        bool ok = true;
        rep(i, G[l].size()) if (!vis[G[l][i]]) ok = false;
        rep(i, G[r].size()) if (!vis[G[r][i]]) ok = false;
        if (ok)
        {
            int now = l;
            cout << len << endl;
            cout << l + 1 << " ";
            while (now != r)
            {
                cout << nxt[now] + 1 << " ";
                now = nxt[now];
            }
            return 0;
        }
        rep(i, G[l].size()) if (!vis[G[l][i]])
        {
            nxt[G[l][i]] = l;
            vis[G[l][i]] = true;
            l = G[l][i];
            len++;
            break;
        }
        rep(i, G[r].size()) if (!vis[G[r][i]])
        {
            nxt[r] = G[r][i];
            vis[G[r][i]] = true;
            r = G[r][i];
            len++;
            break;
        }
    }
}

Measured memory_bytes: 7168
n = int(input())
a = [int(_) for _ in input().split()]
plus = [0] * n
minus = [0] * n
for i in range(n):
    plus[i] = i + a[i]
    minus[i] = i - a[i]
# print(plus)
# print(minus)

d = {}
for i in range((n)):
    if minus[i] in d:
        d[minus[i]] += 1
    else:
        d[minus[i]] = 1
# print(d)

ans = 0
for i in range(n):
    if plus[i] in d:
        ans += d[plus[i]]
print(ans)

Measured memory_bytes: 113884
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

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

    cout << (a <= 5 ? 0 : (a >= 13 ? b : (b / 2))) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>


const int len = 2 * 1e5+5;

int h[len];

int main(void)
{
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i=0;i<n;++i)
	{
		scanf("%d", &h[i]);
	}
	long long int sum=0;
	std::sort(h, h + n);
	for (int i = 0; i < n - k; ++i)
		sum += h[i];
	printf("%lld", sum);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
  int main(){
    lint N,cnt=0,ans=0;
    cin>>N;
    lint X[N];
    rep(i,N){
      cin>>X[i];
    }
    rep(i,N){
      if((i+1)==X[i]){
        cnt++;
        if(i==(N-1))ans+=(cnt+1)/2;
        continue;
      }
      ans+=(cnt+1)/2;
      cnt=0;
    }
  cout<<ans;
  }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
using mp = map<int,int>;
const int MN = 1e5+3, MOD = 1e9+7;
pii dp[MN];
char s[MN];
int main () {
	int n,k;
	scanf ("%d %d %s",&n,&k,s);
	for (int i = 1; i <= n; i++) dp[i].first = MOD;
	dp[0] = {0,-1}; multiset<pii> st = {{0,0}};
	for (int i = 1; i <= n; i++) {
		if (s[i] == '0' && !st.empty()) {
			dp[i] = *st.begin();
			++dp[i].first;
			st.insert({dp[i].first,i});
		}
		if (i >= k && dp[i-k].first < 1e9) st.erase(st.find({dp[i-k].first,i-k}));
	}
	if (dp[n].first == MOD) return !printf ("-1\n");
	vector<int> v;
	int cur = n;
	while (cur) {
		v.push_back(cur-dp[cur].second);
		cur = dp[cur].second;
	}
	reverse(v.begin(),v.end());
	for (int i : v) printf ("%d ",i);
	printf ("\n");
    return 0;
}


Measured memory_bytes: 3712
from random import sample
def gcd(x, y):
    if x < y:# x >= y とする
        x, y = y, x
    r = x % y
    res = y if r == 0 else gcd(y, r)
    return res

n = int(input())

nl = []
for j in range(1, 30000 + 1):
    if (j % 2 == 0 or j % 3 == 0 or j % 5 == 0):
        nl.append(j)
len_nl = len(nl)

while True:
    tl = sample(nl, len_nl)
    g = tl[0]
    total = 0
    for j in range(n):
        g = gcd(g, tl[j])
        total += tl[j]
    if total % 30 != 0:
        continue
    if g != 1:
        continue
    break
print(*tl[:n])

Measured memory_bytes: 7488
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

int main()
{
    ll N, X;
    cin >> N >> X;

    ll cur = 0;
    ll ans = 1;
    for (ll i = 0; i < N; i++)
    {
        ll li;
        cin >> li;
        cur += li;

        if (cur <= X) {
            ans += 1;
        } 
    }
    cout << ans << endl;
}

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

int main(void) {
	vector<int> r;
	while (true)
	{
		int n=0,m=0,a=0;
		scanf("%d %d %d",&n,&m,&a);
		if (n==0 && m==0 && a==0){
			break;
		}
		int map[1001][101]={{0}};
		//create map
		for (int i=0; i<m; i++){
			int h=0,p=0,q=0;
			scanf("%d %d %d",&h,&p,&q);
			map[h][p]=q;
			map[h][q]=p;
		}
		//execute
		int pos = a;
		for (int i=1000; i>0; i--)
		{
			if (map[i][pos] != 0){
				pos = map[i][pos];
			}
		}
		r.push_back(pos);
	}
	for(int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n],dp[n]={0};
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
    dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  if (n%2==0) {
    for (int i=n-1; i>0; i-=2) cout << a[i] << " ";
    for (int i=0; i<n; i+=2) {
      if (i==n-2) cout << a[i] << endl;
      else cout << a[i] << " ";
    }
  }
  else {
    for (int i=n-1; i>=0; i-=2) cout << a[i] << " ";
    for (int i=1; i<n; i+=2) {
      if (i==n-1) cout << a[i] << endl;
      else cout << a[i] << " ";
    }
  }
}

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

int main(){
    string a, b;
    cin >> a >> b;
    int maxsize;
    
    if(a.size() == b.size()){
        
        for(int i = 0; i < a.size(); i++){
           cout << a[i] << b[i];
        }

    }else{
        for(int i = 0; i < a.size() - 1; i++){
             cout << a[i] << b[i];
        }
        cout << a[a.size() - 1];

    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=True
if n==0:
    print(0)
    a=False

lst=[]
while a:
    if n%-2==-1:
        n=n//-2 +1
        lst.append(1)
    else:
        n=n//-2
        lst.append(0)
    if n==1 :
        lst.append(1)
        lst.reverse()
        print(int("".join(list(map(str,lst)))))
        break

Measured memory_bytes: 3060
import time
s = time.time()
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
S = np.array([list(map(int, input().split())) for i in range(D)])

last_day = np.zeros(26, dtype=int)

ans = []
for d in range(1, D+1):
    decrease = c * (d - last_day)
    sd = decrease.sum()
    diff = [S[d-1, i] - sd + decrease[i] for i in range(26)]
    choice = np.argmax(diff)
    ans.append(choice+1)
    last_day[choice] = d

def calc_pre(ans, pre_t, t, d):
    flag1 = flag2 = True
    res = [0, 0]
    for day in range(d-1, -1, -1):
        td = ans[day]
        if td == pre_t and flag1:
            res[0] = td
            flag1 = False
        if td == t and flag2:
            res[1] = td
            flag2 = False
        if not (flag1 or flag2):
            return res
    return res

def calc_next(ans, pre_t, t, d):
    flag1 = flag2 = True
    res = [365, 365]
    for day in range(d+1, D):
        td = ans[day]
        if td == pre_t and flag1:
            res[0] = td
            flag1 = False
        if td == t and flag2:
            res[1] = td
            flag2 = False
        if not (flag1 or flag2):
            return res
    return res

while time.time() - s < 1.9:
    d = np.random.randint(1, D, 1)[0]
    t = np.random.randint(0, 26, 1)[0]
    pre_t = ans[d] - 1
    if pre_t == t:
        continue
    dm1, dm2 = calc_pre(ans, pre_t, t, d)
    dp1, dp2 = calc_next(ans, pre_t, t, d)
    diff = S[d, t] - S[d, pre_t] + c[pre_t]*(dm1-d)*(dp1-d+1) - c[t]*(dm2-d)*(dp2-d+1)
    if diff > 0:
        ans[d] = t + 1

print(*ans, sep='\n')

Measured memory_bytes: 27476
#include <iostream>

using namespace std;

int main(){
 	int n;
  	cin >> n;
  	int T = 0;
  	for(int i = 0; i <= 9; i++){
      for(int j = 0; j <= 9; j++){
        if(n == i*j)
          T = 1;
      }
    }
  	if(T == 1)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

#define COUT cout <<
#define SPACE_COUT << " "  <<
#define COMMA_COUT << ", " <<
#define ENDL << endl;

ll
f(ll b, ll n)
{
    if (n < b) return n;
    ll total = 0;
    while (n > 0) {
        total += n % b;
        n /= b;
    }
    return total;
}

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

    ll n, s;
    cin >> n >> s;

    if (n < s) {
        cout << -1 << endl;
        return 0;
    }

    if (s == n) {
        cout << s+1 << endl;
        return 0;
    }

    for (ll i = 2; i*i <= n; ++i) {
        ll res = f(i, n);
        if (res == s) {
            cout << i << endl;
            return 0;
        }
    }

    ll b_min = LONG_MAX;
    ll p = n -s;
    for (ll i = 1; i*i < n; ++i) {
        if (p % i != 0) continue;
        ll b = (n - s) / i + 1;
        if (n / b + n % b == s) {
            b_min = min(b_min, b);
        }
    }
    if (b_min == LONG_MAX) b_min = -1;        
    cout << b_min << endl;
    return 0;
}


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

#define MAX 256
#define INF 1000000

struct edge {
	int money;
	int time;
};

int main(){
	int n, m;
	int count;
	edge G[120][120];

	while(cin >> n >> m, n || m){
		for(int i=0; i < 120; i++){
			for(int j=0; j < 120; j++){
				G[i][j].money = INF;
				G[i][j].time = INF;
			}
		}
		for(int i=0; i < 120; i++){
			G[i][i].money = 0;
			G[i][i].time = 0;
		}

		for(int i=0; i < n; i++){
			int a, b, mo, t;
			cin >> a >> b >> mo >> t;

			G[a][b].time=t;
			G[a][b].money=mo;
			G[b][a].time=t;
			G[b][a].money=mo;
		}

		for(int k=1; k <= m; k++){
			for(int i=1; i <= m; i++){
				for(int j=1; j <= m; j++){
					G[i][j].time = min(G[i][j].time, G[i][k].time+G[k][j].time);
					G[i][j].money = min(G[i][j].money, G[i][k].money+G[k][j].money);
				}
			}
		}

		cin >> count;
		for(int i=0; i < count; i++){
			int p;
			cin >> n >> m >> p;

			if(p) cout << G[n][m].time << endl;
			else cout << G[n][m].money << endl;
		}
	}

}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, A;
  cin >> N >> A;
  vector<int> X(N);
  rep(i, N) {
    cin >> X[i];
    X[i] -= A;
  }
  int MAX = 105 * 50;
  vector<vector<ll> > dp(N, vector<ll>(MAX));
  rep(i, N) {
    if(i == 0) {
      dp[i][MAX/2+X[i]] += 1;
      dp[i][MAX/2] += 1;
    } else {
      rep(j, MAX) {
        if(j+X[i] >= 0 && j+X[i] < MAX)
          dp[i][j+X[i]] += dp[i-1][j];
        dp[i][j] += dp[i-1][j];
      }
    }
  }
  cout << dp[N-1][MAX/2]-1 << endl;
  return 0;
}



Measured memory_bytes: 2304
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var A = new int[N];
            var _B = new Dictionary<int, int>(N);
            for (int i = 0; i < N; i++)
            {
                A[i] = cin.ReadInt;
                _B.Add(i, cin.ReadInt);
            }
            var B = _B.OrderBy(a => a.Value);
            int total = 0;
            foreach(var item in B)
            {
                total += A[item.Key];
                if(total > item.Value)
                {
                    WriteLine("No");
                    return;
                }
            }
            WriteLine("Yes");

        }

        public void cal(List<int> A, List<int> B, int N)
        {

        }
        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return (a * b) / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 25516
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int merry[] = {1, 4, 1, 4, 1, 2, 1, 2};
		int passenger[];
		int sum, max;
		int digitSum, digitMin;
		int digit;

		passenger = new int[8];
		while (sc.hasNext()) {
			max = 0;
			digitMin = 100000000;
			digit = 0;
			for (int i = 0; i < 8; i++) {
				passenger[i] = sc.nextInt();
			}
			for (int i = 0; i < 8; i++) {
				sum = 0;
				digitSum = 0;
				int k = 10000000;
				for (int j = 0; j < 8; j++) {
					sum += (merry[j] <= passenger[j]) ? merry[j] : passenger[j];
					digitSum += merry[j] * k;
					k /= 10;
				}
				if ((max < sum) || (max == sum && digitSum < digitMin)) {
					max = sum;
					digit = i;
					digitMin = digitSum;
				}
				int swap = merry[0];
				for (int j = 0; j < 7; j++) {
					merry[j] = merry[j + 1];
				}
				merry[7] = swap;
			}
			String s = "";
			for (int i = 0; i < 8; i++) {
				System.out.print(s + merry[(digit + i) % 8]);
				s = " ";
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
n = int(input())
count = 0

if n < 105:
    count = 0
else:
    for i in range(105, n + 1, 2):
        div_count = 0
        for j in range(1, i + 1):
            if i % j == 0:
                div_count += 1
        if div_count == 8:
            count += 1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define f first
#define s second
using namespace std;
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef queue<int> qi;
typedef queue<pii> qpii;


void test_case() {
	int x, n; cin >> x >> n;
	vi bad(300);
	for (int i = 0; i < n; i ++) {
		int y; cin >> y;
		bad[y] = true;
	}
	int ans = -1, odl = INF;
	for (int i = 0; i < 290; i ++) {
		if (!bad[i] && odl > abs(i - x)) {
			odl = abs(i - x);
			ans = i;
		}
	}
	cout << ans << '\n';
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; 
	//cin >> q;
	while (q--) {
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3652
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cum_a = [0] * (n + 1)
for i, v in enumerate(a):
    cum_a[i + 1] = cum_a[i] + a[i]
cum_b = [0] * (m + 1)
for i, v in enumerate(b):
    cum_b[i + 1] = cum_b[i] + b[i]

a_idx = n
b_idx = 0
res = 0
for i in range(n + 1):
    current_a_idx = a_idx - i
    sum_a = cum_a[current_a_idx]
    if sum_a > k:
        continue
    sum_b = cum_b[b_idx]
    while sum_a + sum_b <= k and b_idx < m:
        b_idx += 1
        sum_b = cum_b[b_idx]
        if sum_a + sum_b > k:
            b_idx -= 1
            break
    res = max(b_idx + current_a_idx, res)
a_idx = 0
b_idx = m
for i in range(m + 1):
    current_b_idx = b_idx - i
    sum_b = cum_b[current_b_idx]
    if sum_b > k:
        continue
    sum_a = cum_a[a_idx]
    while sum_a + sum_b <= k and a_idx < n:
        a_idx += 1
        sum_a = cum_a[a_idx]
        if sum_a + sum_b > k:
            a_idx -= 1
            break
    res = max(current_b_idx + a_idx, res)

print(res)

Measured memory_bytes: 48868
n = int(input())
w = list(input() for _ in range(n))
flg = False

for i in range(n-1):
    if(w[i][len(w[i])-1] == w[i+1][0]):
        cnt = 0
        for j in range(n):   
            if(w[j] == w[i]):
                cnt += 1
        if(cnt >= 2):
            flg = False
            break
        else:
            flg = True
    else:
        flg = False
        break
        
print("Yes" if flg else "No")

Measured memory_bytes: 3064
N = int(input())
X = [int(x) for x in input().split()]
Y = sorted(X)
kouho1 = Y[N // 2 - 1]
kouho2 = Y[N//2]
for i in range(N):
    if X[i] <= kouho1:
        print(kouho2)
    else:
        print(kouho1)


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

const int MAXN = 200;
const int MAXK = 100;

int main() {
	string s;
	int k;
	cin >> s >> k;
	int dp[MAXN][MAXK + 1][2];
	memset(dp, 0, sizeof(dp));
	dp[0][0][1] = 1;
	for (int i = 1; i <= s.size(); ++i) {
		dp[i][0][0] = 1;
		dp[i][0][1] = 0;
		for (int j = 1; j <= k; ++j) {
			dp[i][j][0] = dp[i - 1][j][0] + dp[i - 1][j - 1][0] * 9;
			if (s[i - 1] == '0') {
				dp[i][j][1] = dp[i - 1][j][1];
			}
			else {
				dp[i][j][1] = dp[i - 1][j - 1][1];
				dp[i][j][0] += dp[i - 1][j - 1][1] * (s[i - 1] - '0' - 1) + dp[i - 1][j][1];
			}
		}
	}
	cout << dp[s.size()][k][0] + dp[s.size()][k][1] << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
from itertools import combinations
input = sys.stdin.readline

def main():
    h, w, n = map(int, input().split())
    grid = [0]*n
    mod = 10**9
    judge = dict()
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(-1, 2):
            for j in range(-1, 2):
                if a+i <= 1 or a+i >= h or b+j <= 1 or b+j >= w:
                    continue
                if (a+i, b+j) in judge:
                    judge[(a+i, b+j)] += 1
                else:
                    judge[(a+i, b+j)] = 1
   
    ans = [0]*10
    
    for v in judge.values():
        ans[v] += 1
    ans[0] = (h-2)*(w-2)-sum(ans[1:])
    
    for a in ans:
        print(a)

    
if __name__ == "__main__":
    main()


Measured memory_bytes: 164896
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var read = Console.ReadLine();
                var temp_string = read.Split(' ');

                int H = int.Parse(temp_string[0]), W = int.Parse(temp_string[1]);

                if (H == 0 && W == 0)
                    break;

                if(H!=0)
                {
                    for (int i = 1; i < H+1;i++ )
                    {
                        for(int r=1;r<W+1;r++)
                        {

                            switch(i%2)
                            {
                                case 0:
                                    {
                                        if (r % 2 == 1)
                                        {
                                            Console.Write(".");
                                        }
                                        else
                                        {
                                            Console.Write("#");
                                        }
                                        break;
                                    }
                                case 1:
                                    {
                                        if (r % 2 == 0)
                                        {
                                            Console.Write(".");
                                        }
                                        else
                                        {
                                            Console.Write("#");
                                        }
                                        break;
                                    }
                            }
                            
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                }
            }

        }
    }
}

Measured memory_bytes: 8852
import java.util.Scanner;

public class Main {

        public static void main(String[] args){
            Scanner sr = new Scanner(System.in);
            String input = sr.nextLine();
            long inputNum = Long.valueOf(input);
            int sum = 0;
            for(int i=0 ; i <input.length(); i++){
               String num =  input.substring(i, i+1);
               Integer numToInt = Integer.valueOf(num);
               sum += numToInt;
            }

            if(inputNum % sum == 0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }

    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define LB lower_bound
#define UP upper_bound
#define INF 999999999999
const double PI = acos(-1.0);
int A,B,H,M;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> A >> B >> H >> M;
    double h = 30*H+0.5*M;
    double m = 6*M;

    double d = abs(h-m);
    double angle = min(d,360-d);

    double ans = A*A+B*B-2*A*B*cos(angle*PI/180);
    cout << fixed << setprecision(12) << sqrt(ans);
    return 0;     
}



Measured memory_bytes: 4184
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
long long int dp[100001];

/*long long  frogjump(vector<int>v,int n)
{ if(n<=1)
 return 0;
    if(dp[n]!=-1)
      return dp[n];
      
      long long  ans1=abs(v[n]-v[n-1])+frogjump(v,n-1);
      long long  int ans2=abs(v[n]-v[n-2])+frogjump(v,n-2);
      return dp[n]=min(ans1,ans2);
	
	
}*/
long long  frogjump2(vector<int>v,int n,int k)
{ dp[1]=0;
dp[0]=0;
v[0]=10000000;
  for(int i=2;i<=n;i++)
 {   dp[i]=INT_MAX;
   for(int j=1;j<=k;j++)
    {   if(i-j>=0)
       dp[i]=min(dp[i],abs(v[i]-v[i-j])+dp[i-j]);
    }
}
  return dp[n];
	
	
}
int main()
{ 
  int n;
  cin>>n;
  int k;
  cin>>k;
  vector<int> v(n+1);
  for(int i=1;i<=n;i++)
    {
   	  cin>>v[i];
  }
  cout<<frogjump2(v,n,k);
  
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
c = list(map(int, input().split()))
# dp[i][j] = i 番目までを使用して総和がj になる組み合わせ
INF = 5 * 10 ** 4
dp = [[INF] * (n + 1) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    for j in range(n + 1):
        if j >= c[i - 1]:
            dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            )# dp[i - 1][j - c[i - 1]]　だと、複数回　コインを使う場合に対応していない 
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[m][n])




Measured memory_bytes: 43780
#include <iomanip>
#include <cmath>
#include <limits>
#include <iostream>
#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
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n+1); i++)




int main() {
	int N,K;
	cin >> N>>K;
	double po=0;
	rep(i, N) {
		int poi = i;
		double cou = 1;
		while (poi < K) {
			poi *= 2;
			cou=cou/2;
		}
		po += cou;
	}
	cout << fixed << setprecision(10);
	cout << po / N <<endl;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> datos(5);
    for (int &i : datos) cin >> i;
    for (int i = 1; i < 6; i++) {
        if (!datos[i-1]) {
            cout << i << "\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3548
#include<cstdio>
#include<cstring>

char s[120];
int len, ans;

int main() {
    scanf("%s", s);
    len = strlen(s);
    for (int i = 0; i < len >> 1; i++)
        if (s[i] != s[len - i - 1]) ++ans;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

// long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a;
// }

// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }

// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    cout << n*n <<endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int a,b;cin>>a>>b;
  string as=to_string(a),bs=to_string(b);
  string ans0="",ans1="";
  REP(i,0,b)ans0+=as;
  REP(i,0,a)ans1+=bs;
  print((ans0<ans1?ans0:ans1))
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll fenwick[200100];

void add( int a, int x ){
	for( int i = a; i <= 200010; i += ( i & -i ) ) fenwick[i] += x;
}

ll sum( int a ){
	ll res = 0;
	for( int i = a; i > 0; i -= ( i & -i ) ) res += fenwick[i];
	return res;
}

int main(){
	ll n; cin >> n;
	vector<ll> v(n);
	ll maxi = 0;
	for( auto &i : v ){
		cin >> i;
		maxi = max(i, maxi);
	}
	ll thres = n*(n+1)/4;
	ll l = 0, r = maxi+1;
	while( r-l > 1 ){
		ll m = (r+l)/2;
		vector<ll> s(n+1);
		s[0] = 100001;
		for( int i = 1; i <= n; ++i ){
			s[i] = s[i-1] + ( ( v[i-1] >= m ) ? 1 : -1 );
		}
        ll ans = 0;
		memset( fenwick, 0ll, sizeof(fenwick) );
        for( int i = 0; i <= n; ++i ){
            ans += sum(s[i]);
            add( s[i], 1 );
        }
		// cout << l << " " << m << " " << r << " " << ans << endl;
		if( ans >= thres ){
			l = m;
		} else {
			r = m;
		}
	}
	cout << l << endl;
	return 0;
}

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

// Let's just be lazy in typing "typedef"
#define td typedef

// Data types
td long long ll;
td unsigned long long int ull;
td long double ld;

// Containers
td vector<int> vi;
td vector<ll> vll;
td map<int, int> mii;
td map<ll, ll> mll;
td pair<int, int> pii;
td pair<ll, ll> pll;


// Container functions
#define pb push_back
#define mp make_pair
#define n1 first // for pairs
#define n2 second
#define fill(x,v) memset(x,v,sizeof(x))

// Important Constants
#define inf (int)1e9
#define eps (ld)1e-12
#define mod (ll)(1e9 + 7)
#define endl '\n'

// Traversing containers
#define tr(x,itr) for( typeof(x.begin()) itr  = x.begin(); itr!= x.end(); itr++) //Use iterator to iterate from beginning of a data structure to its end
#define all(x) x.begin(),x.end() // all the elements of a DS
#define rep(i,n) for(int i=0;i<n;i++) // increasing for loop from 0 to n
#define inc(i,a,b) for(int i=a;i<=b;i++) //increasing for loop from a to b
#define dec(i,a,b) for(int i=b;i>=a;i--) //decreasing for loop from b to a
#define in(a,b)( (b).find(a) != (b).end()) // check if a is inside b
#define cases ll t;cin>>t;while(t--) // declare testcases, take input and start while loop

#define abs(x) (x<0 ? -x : x)
#define sqr(x) (x*x)

// I/O declare n and take input
#define cint(n) int n;cin>>n

// I/O optimizations
#define io1 ios::sync_with_stdio(false)
#define io2 cin.tie(NULL);cout.tie(NULL)

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

ll lcm(int a, int b){
    return a * b / gcd(a,b);
}

vll h, dp;

int main(){
    io1;
    io2;

    int n, x;
    cin >> n;
    dp.assign(n, inf);
    for(int i=0;i<n;i++)cin>>x,h.pb(x);
    dp[0] = 0;
    dp[1] = abs((h[0] - h[1]));
    for(int i=2;i<n;i++){
        int two = h[i-2] - h[i];
        int one = h[i-1] - h[i];
        dp[i] = min(dp[i-1] + abs(one), dp[i-2] + abs(two));
    }
    cout << dp[n-1] << endl;
    // for(int i=0;i<n;i++)cout << dp[i] << ' ';
    return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>

int main() {
  int i, tmp, a[4] = {0};
  for (i=0; i < 6 ;i++) {
    scanf("%d", &tmp);
    a[tmp-1]++;
  }
  if (a[0] == a[3] && a[0] == 1 && a[1] == a[2]) puts("YES");
  else puts("NO");



  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n,fa[N],a[N];
struct LY { int x,y,id; }b[N];
bool operator < (LY A,LY B)
{
	LL g1=(LL)A.x*B.y,g2=(LL)A.y*B.x;
	return g1==g2?A.id< B.id:g1< g2;
}
set <LY> s;
struct UNION
{
	int fa[N];
	void init (int n) { for (int i=1; i<=n; i++) fa[i]=i; }
	int getf (int x) { return fa[x]==x?x:fa[x]=getf (fa[x]); }
}U;
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n);
	for (int i=2; i<=n; i++)
		sc(fa[i]);
	for (int i=1; i<=n; i++)
		sc(a[i]);
	U.init (n);
	LL ans=0;
	for (int i=1; i<=n; i++)
	{
		b[i]=(LY){a[i]==1,a[i]==0,i};
		if (i> 1) s.insert (b[i]);
	}
	for (int T=1; T< n; T++)
	{
		int x=(*s.begin ()).id,f=U.getf (fa[x]);
		ans+=(LL)b[f].x*b[x].y;
		s.erase (b[x]),s.erase (b[f]);
		b[f].x+=b[x].x,b[f].y+=b[x].y;
		if (f> 1) s.insert (b[f]);
		U.fa[x]=f;
	}
	pr(ans);

    return 0;
}

Measured memory_bytes: 27904
#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

using Result = std::pair<int, int>;
struct Edge {
  int from, to, cost;
  Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};

using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;

Result visit(int p, int v, const Graph &g) {
    cout<<v<<endl;
  Result r(0, v);
  for(auto& e : g[v]) if (e.to != p) {
    Result t = visit(v, e.to, g);
    t.first += e.cost;
    if (r.first < t.first) r = t;
  }
  return r;
}
int diameter(const Graph &g) {
    cout<<"we"<<endl;
  Result r = visit(-1, 0, g);
  Result t = visit(-1, r.second, g);
  return t.first; // (r.second, t.second) is farthest pair
}
int INF = -12;
int bfs01(const Graph &g, int s) {
  int n = g.size();
  std::vector<int> d(n, INF);
  std::deque<int> que;
  que.push_back(s);
  d[s] = 0;
  while (!que.empty()) {
    int cur = que.front();
    que.pop_front();
    for (auto p : g[cur]) {
      int dst = p.to, w = p.cost;
      assert(w == 0 || w == 1);
      if (d[dst] != INF) continue;
      if (w == 0) {
        d[dst] = d[cur];
        que.push_front(dst);
      } else {
        d[dst] = d[cur] + 1;
        que.push_back(dst);
      }
    }
  }
  int res = 0;
  FOR(i,0,n) res = max(res,d[i]);
  return res;
}

bool bi(vector<string> &g, int n){
    vector<int> v(n,-1);
    v[0]  = 0;
    vector<int> used(n);
    deque<int> q;
    q.push_back(0);
    used[0] = 1;

    while(!q.empty()){
        int t = q.front();
        q.pop_front();
        int tmp_n = v[t];        
        FOR(i,0,n){
            int tmp_to = tmp_n ^ (g[t][i] - '0');
            if(tmp_n ^ tmp_to){
                if(used[i] == 0){
                    v[i] = tmp_to;
                    used[i] = 1;
                    q.push_back(i);
                } 
                if(v[i] != tmp_to) return false;
            }
        }
    }
    return true;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<string> v(n);
    Graph g(n);
    FOR(i,0,n){
        cin>>v[i];
        FOR(j,0,n)if(v[i][j] == '1') g[i].emplace_back(Edge(i,j,1));
    }

    if(!bi(v,n)) cout<<-1<<endl;
    else{
        int x = 0;
        FOR(i,0,n)x = max(bfs01(g,i),x);
        cout<<x+1<<endl;
    }
    
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll powmod(ll a, ll b, const ll mod = 1000000007) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b % 2 == 1)res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res;
}


vector<ll> f;
void cominit(ll n = 210000, const ll mod = 1000000007) {
    f.resize(n + 1);
    f[0] = 1;
    REP(i, n)f[i + 1] = f[i] * (i + 1) % mod;
}

ll nCr(ll n, ll r, const ll mod = 1000000007) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * powmod(f[r] * f[n - r], mod - 2, mod) % mod;
}

ll nPr(ll n, ll r, const ll mod = 1000000007) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * powmod(f[n - r], mod - 2, mod) % mod;
}

ll nHr(ll n, ll r, const ll mod = 1000000007) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return nCr(n + r - 1, r, mod);
}

ll k, ans;
string s;
int main() {
    cominit(2100000);
    cin >> k >> s;
    ll sz = s.size();
    ll n = k + sz;
    ans = powmod(26, n);
    REP(i, sz){
        ans -= nCr(n, i) * powmod(25, n - i) % MOD;
        ans = (ans + MOD * 2) % MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 21600
import sys
from collections import deque

def check(Edge, e, N):
    q = deque()
    visited = [False] * N
    for nextNode in Edge[0]:
        if (0, nextNode) != e: q.append((0, nextNode))
    visited[0] = True
    while q:
        preNode, nowNode = q.popleft()
        if not visited[nowNode]:
            visited[nowNode] = True
            for nextNode in Edge[nowNode]:
                if nextNode == preNode: continue
                if (min(nowNode, nextNode), max(nowNode, nextNode)) != e:
                    q.append((nowNode, nextNode))
    return False in visited


def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Edge = [[] for _ in range(N)]
    EdgeN = [None] * M
    for i in range(M):
        a, b = map(int, input().split())
        Edge[a-1].append(b-1)
        Edge[b-1].append(a-1)
        EdgeN[i] = (min(a-1, b-1), max(a-1, b-1))
    count = 0
    for e in EdgeN:
        if check(Edge, e, N): count += 1
    print(count)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3316
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
int c[3][3];
int main(){
    rep(i,3)rep(j,3)cin>>c[i][j];
    rep(k,101){
        rep(i,3){
        if(c[i][0] -1>=0 && c[i][1] -1>=0 &&c[i][2] -1>=0){
            rep(j,3)c[i][j]--;
        }
        }
    }
    rep(i,3){
    if(c[0][i]==c[1][i] && c[0][i]==c[2][i]){
        continue;
    }
    else{
        cout<<"No"<<endl;
        return 0;
    }
    }
    cout<<"Yes"<<endl;
}


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//---------------------------------------------------------------
// シンプル
//---------------------------------------------------------------

int64 X, Y;

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

	cin >> X >> Y;
	int ans = 0;
    while(X <= Y) {
    	X <<= 1;		// ここで２倍にしていく
    	ans++;
    }
    cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256