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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void) {
  while (true) {
    int n, p[105][105], m[105];
    cin >> n;
    if (!n)
      break;
    REP(i, n) {
      cin >> m[i];
      REP(j, m[i]) { cin >> p[i][j]; }
    }
    int k, l[105];
    cin >> k;
    REP(i, k) { cin >> l[i]; }

    int ans = 0;
    REP(i1, n) {
      int ret = 0;
      REP(i2, m[i1]) {
        REP(i3, k) {
          if (p[i1][i2] == l[i3])
            ret++;
        }
      }
      if (ret == k) {
        if (ans == 0)
          ans = i1 + 1;
        else
          ans = -1;
      }
    }
    if (ans == 0)
      ans = -1;

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

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
 
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;
 
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
 
int main() {
    vi v(1000, 0);
    for (int i = 1; i < 1000; i++) v[i] = v[i-1] + i;
 
    int N, cnt;
    while (cin >> N) {
        if (N == 0) break;
        cnt = 0;
        for (int i = 0; i < v.size(); i++) {
            for (int j = i + 2; j < v.size(); j++) {
                if (v[j] - v[i] < N) continue;
                if (v[j] - v[i] == N) cnt++;
                break;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>

int main(void){
  char buff[12];
  int year;
  int manth;
  int day;
  fgets(buff,sizeof(buff),stdin);
  sscanf(buff,"%d/%d/%d",&year,&manth,&day);

  if(year<2019||(year==2019&&manth<5)){
    printf("Heisei");
  }else{
    printf("TBD");
  }

  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for state in range(2**n):
    ons = [0] * m
    for i in range(m):
        for j in ks[i][1:]:
            if( (state >> (j-1)) & 1  ) == 1:
                ons[i] += 1

    light = 0
    for i in range(m):
        if( p[i] == (ons[i] % 2) ):
            light += 1

    if(light == m):
        ans += 1

print(ans)

Measured memory_bytes: 41200
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

signed main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

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

  int result = 0;
  rep(i, N) {
    int A, B; cin >> A >> B;
    if (A>=H && B>=W) result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    if b[i] > a[i]:
        ans += a[i]
        b[i] = b[i] - a[i]
        if b[i] > a[i + 1]:
            ans += a[i + 1]
            a[i + 1] = 0
        else:
            a[i + 1] -= b[i]
            ans += b[i]
            #b[i] = 0
            
    else:
        ans += b[i]
        #b[i] = 0
    #ans += min(a[i] + a[i + 1], b[i])
    #a[i] = max(0, a[i]-b[i])
    #a[i + 1] = max(0, )
    #b[i] = 
print(ans)


Measured memory_bytes: 24152
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

LL n, m;
LL a[101010];

int main(){
    cin >> n >> m;
    REP(i, n)cin >> a[i], a[i] /= 2;
    while(a[0] % 2 == 0){
        REP(i, n){
            if(a[i] % 2){
                cout << 0 << endl;
                return 0;
            }
            a[i] /= 2;
        }
        m /= 2;
    }
    REP(i, n)if(a[i] % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    LL l = a[0];
    REP(i, n)l = lcm(l, a[i]);
    cout << (m / l + 1)/2 << endl;
}

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

int main(){
    int a, b ,c, d;
   cin >> a>> b>>c >>d;
    int m, l;
    if(c%b==0){
        m = c/b;
    }else{
        m = c/b +1;
    }
    if(a%d==0){
        l = a/d;
    }else{
        l = a/d +1;
    }
    if(m>l){
        cout << "No";
    }else{
        cout << "Yes";
    }

}


Measured memory_bytes: 3644
import java.util.*

val A = mutableListOf<String>()
val B = mutableListOf<String>()
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val n = sc.nextInt()
    val m = sc.nextInt()

    for (i in 0 until n) {
        A.add(sc.next())
    }
    for (i in 0 until m) {
        B.add(sc.next())
    }
    for (i in 0 until n) {
        for (j in 0 until n) {
            if (judge(i, j)) {
                println("Yes")
                return
            }
        }
    }
    println("No")
}

fun judge(ni: Int, nj: Int): Boolean {
    val n = A.size
    val m = B.size
    for (i in 0 until m) {
        for (j in 0 until m) {
            when {
                ni + i >= n || nj + j >= n || B[i][j] != A[ni + i][nj + j]
                -> return false
            }
        }
    }
    return true
}


Measured memory_bytes: 29604
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int h,w; cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    REP(i,h) {
        REP(j,w) {
            if(s[i][j]=='.') continue;
            else {
                if(i>0 && s[i-1][j]=='#') continue;
                if(j>0 && s[i][j-1]=='#') continue;
                if(j<w-1 && s[i][j+1]=='#') continue;
                if(i<h-1 && s[i+1][j]=='#') continue;
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//↑templete
int main() {
	int A,B;
	cin>>A>>B;
	if(1<=A && A<=9 && 1<=B && B<=9)
		cout<<A*B<<endl;
	else
		cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353//1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

inline int func(int a, int b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}

int main()
{
	ll x;
	cin >> x;
	ll r = 0;
	r = (x / 500) * 1000;
	x %= 500;
	r += (x / 5) * 5;
	printf("%lld", r);

	return 0;
}


Measured memory_bytes: 888
import math

A, B, H, M = map(int, input().split(' '))
deg = abs((6 * M - (30 * H + 0.5 * M)))
if deg > 180:
    deg = 360 - deg
deg = math.radians(deg)
print(math.sqrt((B - A * math.cos(deg)) ** 2 + (A * math.sin(deg)) ** 2))

Measured memory_bytes: 9520
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = (int)n - 1; i >= 0; --i)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
	string s;
	cin >> s;
	cout << string(s.begin(), s.begin()+4)
		<< " "
		<< string(s.begin()+4, s.end()) << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>

#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)
using namespace std;

int main(void){
	
	int L, A, B, C, D;
	
	cin >> L >> A >> B >>C >>D;
	
	rep(i, L+1){
		if(C*i>=A && D*i>=B){
			printf("%d\n", L-i);
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1144
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> M;
	while (N) {
		vector<bool>flag(N + 1, false);
		flag[1] = true;
		vector<pair<int, pair<int, int>>>edge(M);
		for (int i = 0; i < M; i++) {
			cin >> edge[i].first >> edge[i].second.first >> edge[i].second.second;
		}
		sort(edge.begin(), edge.end());
		for (auto i : edge) {
			if (flag[i.second.first]) {
				flag[i.second.second] = true;
			}
		}
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			if (flag[i]) {
				ans++;
			}
		}
		cout << ans << endl;
		cin >> N >> M;
	}
	return 0;
}

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include <stack>
#include <queue>
#include <map>
#include<math.h>
#include<string.h>

using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define pb push_back

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

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

int MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());
    vector<int> m(9,MOD);
    int ans = 0;
    rep(i,n){
        if(s[i]%10==0){
            ans += s[i];
        }
        else{
            m[s[i]%10 -1] = min(m[s[i]%10 -1],s[i]);
            ans += s[i];
        }
    }
    if(ans%10==0){
        ans -= *min_element(m.begin(),m.end());
        if(ans<0) ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
n, k = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
F = [int(i) for i in input().split()]
F.sort()
"""
n = 11
k = 14
A = [1,1,2,3,3,4,5,5,5,6,9]
F = [9,9,8,8,7,6,4,3,3,2,2]
"""

 
P = [A[i]*F[i] for i in range(n)]
sum_A = sum(A)
 
def b(p):
    result = 0
    for i in range(n):
        if P[i] > p:
            r = (P[i] - p) // F[i]
            if P[i] - r * F[i] > p:
                r += 1
            result += r
    return result
 
if sum_A <= k: print('0')
else: 
    left = 0
    right = max(P)
    middle = int((left + right) / 2)
    bm = b(middle)
    
    
    
    while right - left > 1:
        
        if bm > k: left = middle
        else: right = middle
            
        middle = int((left + right) / 2)
        bm = b(middle)
 
    if b(left) <= k: print(left)
    else: print(right)

Measured memory_bytes: 120652
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

map<int, int> dp;

int getv(int x){
	if (dp.count(x)) return dp[x];
	else return 1e9;
}

void setv(int x, int v){
	if (dp.count(x)){
		dp[x]=min(dp[x], v);
	}
	else{
		dp[x]=v;
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int ct=0;
	string s;
	cin>>s;
	int n=s.size();
	dp[0]=0;
	for (int i=0;i<n;i++){
		ct^=(1<<(s[i]-'a'));
		int tv=getv(ct);
		for (int j=0;j<26;j++){
			tv=min(tv, getv(ct^(1<<j)));
		}
		setv(ct, tv+1);
		if (i==n-1){
			cout<<tv+1<<endl;
			return 0;
		}
	}
}

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

using namespace std;

int main()
{
	long long int A, B, C;
	cin >> A >> B >> C;
	if(A%2==0 || B%2==0 || C%2==0)
	{
		cout << "0";
		return 0;
	}
	if(A>B)
	{
		if(A>C)
		{
			cout << B*C;
		}
		else
		{
			cout << B*A;
		}
	}
	else
	{
		if(B>C)
		{
			cout << A*C;
		}
		else
		{
			cout << A*B;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<vector<ll>> g(n);
    REP(i, n-1) {
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    ll root = 0;
    REP(i, n) if(g[root].size() < g[i].size()) root = i;

    function<ll(ll,ll)> dfs = [&](ll v, ll p) {
        ll cnt = 0, ret = 0;
        for(auto to: g[v]) if(to != p) {
            ll val = dfs(to, v);
            if(val == 0) cnt++;
            ret += val;
        }
        if(cnt > 1) ret += cnt-1;
        return ret;
    };
    
    ll ans = dfs(root, -1);
    chmax(ans, 1LL);
    cout << ans << endl;

    return 0;
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

ll n, d;

ll dist(ll x, ll y)
{
    return x*x + y*y;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    clock_t ck;
    ck = clock();
    cin >> n >> d;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        if (dist(x,y) <= d*d)
            ans++;
    }
    cout << ans << '\n';
    ck = clock()-ck;
    cerr << "It took " << 1.0*ck/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N  = 1e6 + 69, INF = 1e9;

const ll INFLL = 1e18;

int n, k;
ll dp[3009][3009],A[N];

int main(){

        cin >> n;

        for(int i = 1; i <= n; i++){
                cin >> A[i];
        }

        for(int cnt = 1; cnt <= n; cnt++){
                for(int l = 1; l <= n; l++){
                        int r = l + cnt - 1;
                        if(r > n) continue;
                        if(l == r){
                                dp[l][r] = A[l];
                        } else {
                                dp[l][r] = max(A[l] - dp[l+1][r], A[r] - dp[l][r-1]);
                        }
                }
        }

        cout << dp[1][n] << endl;
}


Measured memory_bytes: 72064
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n,m;
vector<int> to[50];
int gg[60];
void solve(int i, int p,int x,int y){
    for(int u : to[i]){
        if(u==p) continue;
        if(gg[u]==1) continue;
        else if((i==x && u==y) || (i==y && u==x)) continue;
        if(gg[u]==0){
            //cout<<i<<" "<<u<<endl;
            gg[u]=1;
            solve(u,i,x,y);
        }
    }
}

int main(){
    cin>>n>>m;
    int a,b;
    rep(i,m){
        cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    int cnt = 0;
    for(int i = 0; i< n; i++){
        for(int u : to[i]){
            rep(j,60) gg[j]=0;
            int x = i;
            int y = u;
            //i,u の辺を無視
            //cout<<x<<" "<<y<<" "<<"start"<<endl;
            solve(0,-1,x,y);
            //cout<<"finish"<<endl;
            bool ok = 1;
            rep(i,n){
                if(i==0) continue;
                else if(gg[i]==0) ok = 0;
            }
            if(ok == 0){
                cnt++;
                //cout<<x<<" "<<y<<" "<<"is hashi"<<endl;
            }
        }
        /*
        bool ok = 1;
        rep(i,n){
            if(i==0) continue;
            else if(gg[i]==0) ok = 0;
        }
        */
       /*
        if(ok){
            cnt++;
             cout<<x<<" "<<y<<" "<<"is hashi"<<endl;
        }
        */
    }
    cout<<cnt/2<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
  public static void main(String[] args) throws Exception{
    FastScanner sc = new FastScanner(System.in);
    int s = sc.nextInt();
    int w = sc.nextInt();
    
    new Solution(s, w);
  }
}

class Solution {
  public Solution(int s, int w) {
    if(s <= w) System.out.println("unsafe");
    else System.out.println("safe");
    // System.out.println(res);
  }
}


class FastScanner {
  private final InputStream in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  public FastScanner(InputStream source) {
    in = source;
  }

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) return buffer[ptr++];
    else return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext()) throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
      throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 32472
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005, INF = 1e9;
int n, u, v, a, b, d[2][MX], ans;
vector<int> G[MX];
void dfs(int u, int p, int t){
	if(u!=p) d[t][u] = d[t][p]+1;
	for(int ch: G[u]) if(ch != p && d[!t][ch] > d[t][u]+1) dfs(ch,u,t);
}

int main(){
	scanf("%d%d%d", &n, &u, &v);
	u--; v--;
	rep(i,n-1){
		scanf("%d%d", &a, &b);
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	fill(d[1],d[1]+n,INF);
	dfs(v,v,0);
	d[1][u] = 0;
	dfs(u,u,1);
	rep(i,n) if(d[1][i] != INF) ans = max(ans,d[0][i]-1);
	printf("%d\n", ans);
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    string S;
    cin >> S;
    int S_size = (int)S.size();
    string S1="";
    string S2="";
    
    rep(i,S_size){
        if(i < S_size/2){
            S1 += S[i];
        }else{
            S2 += S[i];
        }
    }

    while(true){
        string s = S1.substr((int)S1.size() - 1, 1);
        S1 = S1.erase((int)S1.size() - 1);
        S2 = s + S2;
        S2 = S2.erase((int)S2.size() - 2);
        if(S1 == S2){
            int ans = 2*(int)S1.size();
            cout << ans << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

    int N, K;
    cin >> N >> K;
    int A[N];
    vector<int> vecp, vec0, vecm;
    rep(i,N){
        cin >> A[i];
        if(A[i] > 0) vecp.push_back(A[i]);
        else if(A[i] == 0) vec0.push_back(A[i]);
        else vecm.push_back(-A[i]);
    }
    int np = vecp.size();
    int n0 = vec0.size();
    int nm = vecm.size();
    if(np*nm < K && K <= np*nm + n0 *(N-1) - n0*(n0-1)/2){
        cout << 0 << endl;
        return 0;
    }
    sort(vecp.begin(), vecp.end());
    sort(vecm.begin(), vecm.end());
    int left = 0, right = INF, mid;

    if(np*nm >= K){
        while(right - left > 1){
            mid = (left+right)/2;
            int cou = 0;
            for(int w : vecm){
                int Q = (mid+w-1)/w;
                cou += vecp.end() - lower_bound(vecp.begin(), vecp.end(), Q);
            }
            if(cou >= K) left = mid;
            else right = mid;
        }
        cout << -left << endl;
    }
    else{
        K = N*(N-1)/2 - K + 1;
        while(right -left > 1){
            mid = (left+right)/2;
            int cou = 0;
            for(int w : vecm){
                int Q = (mid+w-1)/w;
                cou += vecm.end() - lower_bound(vecm.begin(), vecm.end(), Q);
                if(w >= Q) --cou;
            }
            for(int w : vecp){
                int Q = (mid+w-1)/w;
                cou += vecp.end() - lower_bound(vecp.begin(), vecp.end(), Q);
                if(w >= Q) --cou;
            }
            if(cou/2 >= K) left = mid;
            else right = mid;
        }
        cout << left << endl;
    }
}

Measured memory_bytes: 3700
from functools import lru_cache
cc = [["." for i in range(8)] for j in range(8)]

def check(cc,a,b):
    ss = list(zip(*cc))
    if 'Q' in cc[a]: return False
    if 'Q' in ss[b]: return False
    d = []
    for i in range(8):
        for j in range(8):
            try:
                if j + (a - i) == b: 
                    d.append(cc[i][j])
                if j -  (a - i) == b:
                    d.append(cc[i][j])
                if j + (i - a) == b: 
                    d.append(cc[i][j])
                if j -  (i - a) == b:
                    d.append(cc[i][j])
            except IndexError: continue
    if 'Q' in d: return False
    return True

def chess(s,queen):
    if queen == 8:
        return s
    for i in range(8):
        for j in range(8):
            if check(s,i,j):
                sol = s
                sol[i][j] = 'Q'
                if chess(sol,queen+1) != [[]]:
                    return sol
                else: sol[i][j] = "."
    return [[]]


k = int(input())
for i in range(k):
    a, b = input().split()
    cc[int(a)][int(b)] = 'Q'
ans = chess(cc,k)
print('\n'.join(list(map(lambda x: ''.join(x),ans))) )


Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int N;
    cin >> N;
    V(string) S(N);
    rep(i, N) cin >> S[i];

    int res = 0;
    rep(i, N) {
        bool ok = true;
        rep(y, N) {
            rep(x, N) {
                if(S[y][(i+x)%N]!=S[x][(i+y)%N]) {
                    ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
        if(ok) res++;
    }

    cout << res*N << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,len;
    string ch;
    cin>>n>>ch;
    len=ch.size();
    for(i=0;i<len;i++)
    {
      if((ch[i]+n)>90)
      {
          ch[i]=(ch[i]+n)-26;
      }
      else
      {
          ch[i]=ch[i]+n;
      }
      cout<<ch[i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> A(n);
    long sum=0;
    for(int i=0;i<n;i++){
        cin>>A.at(i);
        sum+=A.at(i);
    }
    sort(A.begin(),A.end());
    cout<<A.at(0)<<" "<<A.at(n-1)<<" "<<sum<<endl;
}


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

using namespace std;

int a[111];

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n - 1; i++){
        scanf("%d", a + i);
    }
    int ans = 0;
    int cur = INT_MAX;
    for (int i = n - 1; i >= 1; i--){
        ans += min(a[i], cur);
        cur = a[i];
    }
    printf("%d\n", ans + cur);
    return 0;
}


Measured memory_bytes: 256
function main(input) {
    const args = input.split('\n')
    const A = parseInt(args[0],10),
	  B = parseInt(args[1],10),
	  C = parseInt(args[2],10),
	  X = parseInt(args[3],10);

    var count = 0;

    for(var a = 0;a <= A; ++a){
	for(var b = 0;b <= B;++b){
	    for(var c = 0; c <= C; ++c){
		var sum = (a * 500) + (b * 100) + (c * 50);
		if(sum === X) ++ count;
	    }
	}
    }
    console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
a = [[0 for i in range(9)] for j in range(9)]
for i in range(1,int(input())+1):
  i = str(i)
  if i[-1] != "0":
   	a[int(i[0])-1][int(i[-1])-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    if i != j:
      ans += a[i][j]*a[j][i]
    else:
      ans += a[i][j] ** 2
print(ans)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int s = in.nextInt();
		long ans = doCal(s);
		System.out.println(ans);
	}

	static long[] stCal = new long[2001];

	private static long doCal(int s) {
		if (s < 3)
			return 0;
		if (s < 6)
			return 1;
		if (stCal[s] > 0)
			return stCal[s];
		long ans = 1;
		for (int i = 3; i < s; i++) {
			ans += doCal(s - i);
			ans %= 1000000007;
			// System.out.println(s-i+" "+ans);
		}
		// System.out.println(ans);
		stCal[s] = ans;
		return ans;
	}

}


Measured memory_bytes: 35836
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.trim();
    var S = input.split('\n')[0];
    var T = input.split('\n')[1];
    var ans = T.slice(0, -1);
    if (ans === S) {
        console.log("Yes");
    } else {
        console.log("No");
        
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    to = [[None]*n for _ in range(60)]
    to[0] = a[:]
    for i in range(1, 60):
        for j in range(n):
            to[i][j] = to[i-1][to[i-1][j]-1]
    p = 1
    for i in range(59, -1, -1):
        num = 1 << i
        if k >= num:
            k -= num
            p = to[i][p-1]
    print(p)
            

if __name__ == "__main__":
    main()

Measured memory_bytes: 184192
//https://atcoder.jp/contests/abc075/tasks/abc075_b

#include <iostream>
using namespace std;

int main(void){
    int H,W;
    int counter = 0;
    // string S[51][51];
    string S[50];

    cin >> H >> W;
    for (int i = 0; i < H; i++){
        cin >> S[i];
    }
    // for (int i = 0; i < H; i++){
    //         cout << S[i] << endl;
    // }

    // string num[H][W];
    // int num[H][W];
    // for (int i = 0; i < H; i++){
    //     for (int j = 0; j < W; j++){
    //         num[H][W] = 0;
    //     }
    // }
    int dx[8] = {1,0,-1,0,1,-1,-1,1};
    int dy[8] = {0,1,0,-1,1,1,-1,-1};
    int ii = 0;
    int jj = 0;

    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            counter = 0;
            // if (S[i][j] == '.') printf("S[%d][%d]=clear\r\n",i,j);
            if (S[i][j] == '.'){
                // for (int p = i-1; p <= i+1; p++){
                //     for (int q = j-1; q <= j+1; q++){
                //         if(p >= 0 && q >= 0 && p < H && q < W && S[p][q] == '#') counter ++;
                //     }
                // }
                // num[i][j] = counter;
                // printf("num[%d][%d] = %d\r\n",i,j,num[i][j]);

                for (int k = 0; k < 8; k++){
                    ii = i + dx[k];
                    jj = j + dy[k];
                    if(ii >= 0 && jj >= 0 && ii < H && jj < W && S[ii][jj] == '#') counter ++;
                }
                S[i][j] = '0' + counter;
            }
        }
    }
    // for (int i = 0; i < H; i++){
    //     for (int j = 0; j < W; j++){
    //         if (S[i][j] == '.'){
    //             S[i][j] = char('0' + num[i][j]);
    //         }
    //     }
    // }
    for (int i = 0; i < H; i++) {
        cout << S[i] << endl;
    }

    return 0;
}

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

class FC {
public:
	int p[31];
	int n;

	bool is_over()
	{
		return p[1] == p[2] && p[2] == p[3] && p[3] == p[4] && p[4] == p[5] &&
			   p[5] == p[6] && p[6] == p[7] && p[7] == p[8] && p[8] == p[9] &&
			   p[10] == p[11] && p[11] == p[12] &&
			   p[13] == p[14] && p[14] == p[15] &&
			   p[16] == p[17] && p[17] == p[18] &&
			   p[19] == p[20] && p[20] == p[21] &&
			   p[22] == p[23] && p[23] == p[24] && p[24] == p[25] && p[25] == p[26] &&
			   p[26] == p[27] && p[27] == p[28] && p[28] == p[29] && p[29] == p[30];
	}
	void rot1()
	{
		swap(p[7], p[22]); swap(p[8], p[23]); swap(p[9], p[24]);
		swap(p[13], p[18]); swap(p[10], p[12]);
	}
	void rot2()
	{
		swap(p[1], p[28]); swap(p[2], p[29]); swap(p[3], p[30]);
		swap(p[15], p[16]); swap(p[21], p[19]);
	}
	void rot3()
	{
		swap(p[1], p[24]); swap(p[4], p[27]); swap(p[7], p[30]);
		swap(p[10], p[21]); swap(p[16], p[18]);
	}
	void rot4()
	{
		swap(p[3], p[22]); swap(p[6], p[25]); swap(p[9], p[28]);
		swap(p[12], p[19]); swap(p[13], p[15]);
	}
};

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

	for (int i = 0; i < N; i++) {
		FC now;
		for (int j = 1; j <= 30; j++) {
			cin >> now.p[j];
		}
		now.n = 0;

		queue<FC> que;
		que.push(now);

		while (!que.empty()) {
			now = que.front();
			que.pop();

			if (now.is_over()) {
				cout << now.n << endl;
				break;
			}

			FC nex1 = now; nex1.rot1(); nex1.n++; que.push(nex1);
			FC nex2 = now; nex2.rot2(); nex2.n++; que.push(nex2);
			FC nex3 = now; nex3.rot3(); nex3.n++; que.push(nex3);
			FC nex4 = now; nex4.rot4(); nex4.n++; que.push(nex4);
		}
	}
	return 0;
}

Measured memory_bytes: 13932
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>

using namespace std;
static const int INF = 1e9;
typedef pair<int, int> P;

void solve()
{
	int N, T;
	cin >> N >> T;
	vector<int> A(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	int cur = A[0];
	int maxval = -1;
	int cnt = 0;
	for (int i = 1; i < N; ++i)
	{
		if (cur > A[i])
		{
			cur = A[i];
		}
		else if (A[i] - cur == maxval)
		{
			++cnt;
		}
		else if (A[i] - cur > maxval)
		{
			maxval = A[i] - cur;
			cnt = 1;
		}
	}
	cout << cnt << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 640
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//void scan(string &s) {int c;do{c=gcu();s+=c;}while(!(c=='\n'||c==' '));}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

typedef vector<int> v;

int main() {
	int n, p;
	while ((n = in())) {
		p = in();
		v C(n);
		int b = p, res = -1;
		for (;;) {
			for (auto &c : C) {
				if (b) {
					b--, c++;
					if (c == p) {
						res = &c - &C[0];
						goto end;
					}
				} else
					b += c, c = 0;
			}
		}
end:
		out(res, '\n');
	}
}


Measured memory_bytes: 2556
import math as m
import time
import itertools 
from Queue import Queue

def list_to_int(numList):         # [1,2,3]
    s = map(str, numList)   # ['1','2','3']
    s = ''.join(s)          # '123'
    s = int(s)              # 123
    return s

class Program:
    
    def main(self):
        S = map(int,list(raw_input()))
        l = len(S)
        all_v = 0
        for i in itertools.product([0,1],repeat=l-1):
            i = list(i)
            #https://teratail.com/questions/26730
            indexes = [i+1 for i, x in enumerate(i) if x == 1] 
            indexes.reverse()
            s = list(S)
            v = 0
            for index in indexes:
                v += list_to_int(s[index:])
                s = s[:index]
            v += list_to_int(s)
            all_v += v
        print all_v

if __name__ == '__main__':
    p=Program();
    p.main()

Measured memory_bytes: 3052
N = int(input())
S = list(input())
for i,s in enumerate(S):
    S[i] = int(s)

res = 0
first_index = [-1 for i in range(10)]
second_index = [[-1 for i in range(10)] for j in range(10)]

first_map = set()
second_map = [set() for i in range(10)]
third_map = [[set() for i in range(10)] for j in range(10)]

for i,s in enumerate(S):
    if(first_index[s] == -1):
        first_index[s] = i
        first_map.add(s)
    if(len(first_map) == 10):
        break
for first in first_map:
    for i,s in enumerate(S[first_index[first]+1:]):
        if(second_index[first][s] == -1):
            second_index[first][s] = first_index[first]+1+i
            second_map[first].add(s)
        if(len(second_map[first]) == 10):
            break
for first in first_map:
    for second in second_map[first]:
        for i,s in enumerate(S[second_index[first][second] + 1:]):
            if(s not in third_map[first][second]):
                res += 1
                third_map[first][second].add(s)
            if(len(third_map[first][second]) == 10):
                break
print(res)


Measured memory_bytes: 3848
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main() {
      int n;
      ll a;
      string s;
      cin >> n;
      map<ll, ll> mp;
      for (int i = 0; i < n; i++) {
        int tmp[26] = { };
        cin >> s;
        for (char c : s) {
          tmp[c - 'a']++;
        }
        a=0;
        for (int j = 0; j < 26; j++) {
          a = a * 11LL + tmp[j];
        }
        mp[a]++;
      }
      ll ans = 0;
      for (auto it = mp.begin(); it != mp.end(); it++) {
        int s = it->second;
        ans += (ll) s * (s - 1) / 2;
      }
      cout << ans;
      return 0;
    }

Measured memory_bytes: 6528
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

using Graph=vector<vector<int>>;





void bfs(Graph &G,int s,int g,vector<int> &prev){
    // BFS のためのデータ構造
    vector<int> dist(G.size(),-1);
    queue<int> que;
    // 初期条件 (頂点 0 を初期ノードとする)
    dist[s] = 0;
    que.push(s); // 0 を橙色頂点にする
    
    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
    
        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
    
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
            prev[nv]=v;
        }
    }

}


int main(){
    int N;
    cin>>N;
    Graph G(N);
    REP(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int M;
    cin>>M;
    vector<int> u(M),v(M);
    REP(i,M){
        cin>>u[i]>>v[i];
        u[i]--;
        v[i]--;
    }
    vector<vector<pair<int,int>>> list(M);

    REP(i,M){
        vector<int> prev(N,-1);
        bfs(G,u[i],v[i],prev);
        int s=v[i];
        while(s!=u[i]){
            int nv=prev[s];
            list[i].push_back(make_pair(min(s,nv),max(s,nv)));
            s=nv;
        }
        
    }
    


    ll ans=pow(2,N-1);
    
    REP2(bit,1,1<<M){
        ll cnt=0;
        set<pair<int,int>> used;
        REP(i,M){
            ll mask=1<<i;
            if(bit&mask){
                cnt++;
                REP(j,list[i].size()){
                    used.insert(list[i][j]);
                }
            }
        }
        ll tmp=pow(2,N-1-used.size());
        ans-=pow(-1,cnt-1)*tmp;
    }
    cout<<ans<<endl;


    
}

Measured memory_bytes: 4088
import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  solve()
  @tailrec def solve(): Unit = {
    val rank = readLong()
    if (rank == 0) return
    println(solve(rank))
    solve()
  }
  def countDigit(digit: Int): Long = {
    digit match {
      case 0 | 1 ⇒ 0
      case _ ⇒ 36 * ((1L << digit) - 2) + 9 * ((1L << (digit - 1)) - 1)
    }
  }
  def make(firstDigit: Int, digit: Int, rank: Long): List[Int] = {
    var rest = rank
    for (i ← 0 until 10) {
      if (i == firstDigit) {
        if (rest < 9 * ((1L << (digit - 1)) - 1)) {
          return firstDigit :: make(firstDigit, digit - 1, rest)
        }else {
          rest -= 9 * ((1L << (digit - 1)) - 1)
        }
      }else {
        if (rest < (1L << (digit - 1))) {
          val min = Math.min(firstDigit, i)
          val max = Math.max(firstDigit, i)
          return if (digit > 1) i::rest.toBinaryString.rightJust(digit - 1){'0'}.map{
            case '0' ⇒ min
            case '1' ⇒ max
          }.toList else List(i)
        }else {
          rest -= 1L << (digit - 1)
        }
      }
    }
    ???
  }
  def calDigit(rank: Long, digit: Int): Int = {
    if (rank < countDigit(digit)) {
      digit
    }else {
      calDigit(rank - countDigit(digit), digit + 1)
    }
  }
  def solve(rank: Long): String = {
    val digit = calDigit(rank - 1, 2)
    var rest = rank - 1 - (2 until digit).map(countDigit).sum
    for (i ← 1 until 10) {
      if (rest >= 9 * ((1L << (digit - 1)) - 1)) {
        rest -= 9 * ((1L << (digit - 1)) - 1)
      }else {
        return (i::make(i, digit - 1, rest)).mkString("")
      }
    }
    ???
  }
  implicit class StringExtension(val str: String) extends AnyVal {
    def rightJust(length: Int)(word: ⇒ Char): String = {
      if (str.length < length) word.toString * (length - str.length) + str
      else str
    }
  }
}


Measured memory_bytes: 44892
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin>>n;
    if(n<105)
        cout<<0<<endl;
    else
    {
        vector<ll>v;
        ll c=0;
        for(ll i=105;i<=n;i+=2)
        {
            for(ll j=1;j*j<=i;++j)
            {
                if(i % j == 0)
                {
                    v.push_back(j);
                    v.push_back(j/i);
                }
            }
            if(v.size()==8)
                ++c;
            //cout<<v.size()<<endl;
            v.clear();
        }
        cout<<c<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int p[]=new int[N+1];
		for(int i=1;i<=N;i++) {
			p[i]=sc.nextInt();
		}
		int c=0;
		for(int i=1;i<=N;i++) {
			if(i==p[i]) {
				c++;
				i++;
			}
		}
		
		System.out.println(c);
	}
}


Measured memory_bytes: 49848
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <memory.h>

// pi = atan(1)*4;

#define INTMAX 2100000000

using namespace std;

int main(void)
{
	map <char, int> count[51];
	int n;
	string str;

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> str;
		for (int j = 0; j < str.size(); j++)
		{
			count[i][str[j]] += 1;
		}
	}

	str = "";
	for (char c = 'a'; c <= 'z'; c++)
	{
		int Min = INTMAX;
		for (int i = 1; i <= n; i++)
		{
			Min = min(Min, count[i][c]);
		}
		for (int i = 0; i < Min; i++)
		{
			str += c;
		}
	}

	cout << str << '\n';
	return 0;
}

Measured memory_bytes: 256
n = int(input())

t, x, y = 0, 0, 0
flag = True
for i in range(n):
    ti, xi, yi = map(int, input().split())
    dist = abs(xi-x) + abs(yi-y)
    dt = ti - t
    if dist <= dt and dist % 2 == dt % 2:
        flag = True
    else:
        flag = False
        break
    t, x, y = ti, xi, yi

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

int h, w;
char a[1001][1001];
ll dp[1001][1001];

ll solve() {

	dp[h - 1][w - 1] = 1;
	for (int i = h - 1; i >= 0; i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (a[i][j] != '#' and !(i == h - 1 and j == w - 1)) {
				dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
			}
		}
	}
	return dp[0][0];
}

int main() {

	cin >> h >> w;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> a[i][j];
		}
	}

	memset(dp, 0, sizeof(dp));
	cout << solve();

	return 0;
}

Measured memory_bytes: 9088
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
using namespace std;
#define ull unsigned long long
#define llong long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()


int main() {
	string s;
	cin >> s;
	int n = s.length();
	vector<int> cc(3, 0);
	rep(i, n) {
		if (s[i] == 'a')cc[0]++;
		if (s[i] == 'b')cc[1]++;
		if (s[i] == 'c')cc[2]++;
	}
	int a, b, c;
	sort(all(cc));
	a = cc[2];
	b = cc[1];
	c = cc[0];
	if (a - b > 1) {
		cout << "NO" << endl;
	}
	else {
		if (a == b) {
			if (c >= b - 1) {
				cout << "YES" << endl;
			}
			else cout << "NO" << endl;
		}
		else {

			if (b == c) {
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
		}
	}
	return 0;
}





Measured memory_bytes: 512