akhauriyash/Code-Regression huggingface dataset:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N, M = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(M)]
    P = list(map(int, input().split()))
    answer = 0
    for i in range(2 ** N):
        switch = [0 for _ in range(M)]
        for j in range(N):
            for m in range(M):
                if (i >> j) & 1:
                    if (j + 1) in S[m][1:]:
                        switch[m] += 1
        check = 0
        for m in range(M):
            if switch[m] % 2 == P[m]:
                check += 1

        if check == M:
            answer += 1

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.*;
    
public class Main {
  private static Scanner sc = new Scanner(System.in);
  public static void main(String...args) {
    while(sc.hasNext()) {
      final int n = sc.nextInt();
      final int r = sc.nextInt();
      if (n == 0 && r == 0)
        break;
      solve(n, r);
    }
  }
  private static int case_num = 1;
  private static void solve(final int n, final int r) {
    final int[] p = new int[r];
    final int[] c = new int[r];
    for(int i = 0; i < r; i++) {
      p[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    int ans = 0;
    for(int i = r - 1; i >= 0; i--)
      if(ans < c[i])
        ans += p[i] - 1;
      else if(ans < p[i] - 1 + c[i])
        ans -= c[i];
    System.out.println(n - ans);
  }
}

Measured memory_bytes: 12000
#include <stdio.h>
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}
int  tr['T'+1];
char f[33554432];
int main()
{
	int n, k, c;
	tr['A'] = 0, tr['C'] = 1, tr['G'] = 2, tr['T'] = 3;
	n = in();
	while (n--) {
		if (gc() == 'i') {
			k = 7; while (--k) gc();
			k++; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
			f[k] = 1;
		} else {
			k = 5; while (--k) gc();
			k++; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
			if (f[k]) pc('y'), pc('e'), pc('s');
			else      pc('n'), pc('o');
			pc('\n');
		}
	}
	return 0;
}


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

using namespace std;

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

#define ll long long

int main()
{
	string s, t;
	vector<int> rs(26, -1), rt(26, -1);
	cin >> s >> t;
	rep (i, s.size()) {
		int a = s[i] - 'a';
		int b = t[i] - 'a';
		if (rs[a] != -1 || rt[b] != -1) {
			if (rs[a] != b || rt[b] != a) {
				cout << "No" << endl;
				return 0;
			}
		}
		rs[a] = b;
		rt[b] = a;
	}
	cout << "Yes" << endl;
}



Measured memory_bytes: 776
n,m=map(int, input().split())
pre=[0]*n
c=[[j]+[int(i) for i in input().split()] for j in range(m)]
c=sorted(c, key=lambda city: city[2])
newc=[]
for ci in c:
    pre[ci[1]-1]+=1
    newc.append(ci+[pre[ci[1]-1]])
newc=sorted(newc, key=lambda city: city[0])
for city in newc:
    p=str(city[1])
    cnt=str(city[3])
    ans='0'*(6-len(p))+p+'0'*(6-len(cnt))+cnt
    print(ans)

Measured memory_bytes: 41188
from collections import defaultdict, deque

n = int(input())

nodes = defaultdict(list)
edges = []
edge_count = defaultdict(int)
node = defaultdict(int)
node_num = defaultdict(int)

for _ in range(n - 1):
    a, b = map(int, input().split())
    nodes[a].append(b)
    nodes[b].append(a)
    edges.append((a, b))
    edge_count[a] += 1
    edge_count[b] += 1

c = list(map(int, input().split()))
c.sort(reverse=True)

q = deque()
q.append(1)
node[1] = 0

while q:
    current = q.popleft()
    depth = node[current]

    for next in nodes[current]:
        if next not in node:
            node[next] = depth + 1
            q.append(next)


depth_list = sorted(node.items(), key=lambda x:x[1])

for i, e in enumerate(depth_list):
    node_num[e[0]] = c[i]

ans = 0
for edge in edges:
    ans += min(node_num[edge[0]], node_num[edge[1]])

print(ans)

position = []

for i in range(n):
    position.append(node_num[i + 1])

print(*position, sep=" ")


Measured memory_bytes: 9348
n = int(input())
xyh = [[int(i) for i in input().split()] for j in range(n)]
xyh.sort(key=lambda x: x[2], reverse=True)

for i in range(101):
    for j in range(101):
        h = xyh[0][2] + abs(xyh[0][0] - i) + abs(xyh[0][1] - j)
        for k in xyh:
            if k[2] == max(h - abs(k[0] - i) - abs(k[1] - j), 0):
                continue
            else:
                break
        else:
            print(i, j, h)


Measured memory_bytes: 3064
from collections import Counter
from functools import reduce

H,W=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]

for k in range(10):
	for i in range(10):
		for j in range(10):
			c[i][j] = min(c[i][j], c[i][k] + c[k][j])

A=Counter(map(int, reduce(lambda a,b: a+b, [input().split() for _ in range(H)])))
print(sum([c[i][1] * A[i] for i in range(10) if i in A]))


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

int main()
{
	double x;
	double ans;

	cin >> x;

	for (double i = 2; i <= 10; ++i)
	{
		for (double j = 1; j <= sqrt(x); ++j)
		{
			if (pow(j, i) <= x && pow(j, i) > ans )
			{
				ans = pow(j, i);
			}
		}
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int n = sc.nextInt();

			int ac = 0;
			int wa = 0;
			int tle = 0;
			int re = 0;

			for (int i = 0; i < n; i++) {
				String line = sc.next();

				switch (line) {

				case "AC":
					ac++;
					break;
				case "WA":
					wa++;
					break;
				case "TLE":
					tle++;
					break;
				case "RE":
					re++;
					break;
				}

			}

			System.out.println("AC x " + ac);
			System.out.println("WA x " + wa);
			System.out.println("TLE x " + tle);
			System.out.println("RE x " + re);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 58044
#include <cstdio>
#include <cctype>

using namespace std;

char s[111];
int cur,len;

int shiki();

int kazu()
{
  if( s[cur] == '(' ) {
    cur += 1;
    int s = shiki();
    cur += 1;
    return s;
  } else {
    int a = s[cur]-'0';
    cur += 1;
    while( isdigit(s[cur]) ) {
      a *= 10;
      a += s[cur]-'0';
      cur += 1;
    }
    return a;
  }
}          

int kou()
{
  int a = kazu();
  while( s[cur] == '*' || s[cur] == '/' ) {
    char o = s[cur]; cur += 1;
    int b = kazu();
    o=='*'?(a*=b):(a/=b);
  }
  return a;
}

int shiki()
{
  int a = kou();
  while( s[cur] == '+' || s[cur] == '-' ) {
    char o = s[cur]; cur += 1;
    int b = kou();
    if( o == '+' ) a += b;
    else a -= b;
  }
  return a;
}

int parse()
{
  len = 0;
  while( s[len] ) len++;
  len--;
  cur = 0;
  return shiki();
}

int main(void)
{
  int n; scanf("%d",&n);
  while( n-- ) {
    scanf("%s",s);
    printf("%d\n",parse());
  }
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

//??¨???????????°?????°?????±?????????????´¢
void dfs_visit(int u){
    int v;
    color[u]=GRAY;
    //???????????????
    d[u]=++tt;
    for(v=0;v<n;v++){
        if(M[u][v]==0)
            continue;
        if(color[v]==WHITE)
            dfs_visit(v);
    }
    color[u]=BLACK;
    //????????????
    f[u]=++tt;
}

void dfs(){
    int u;
    //????§????
    for(u=0;u<n;u++)
        color[u]=WHITE;
    tt=0;
    
    for(u=0;u<n;u++)
        //??\????????????u?????????????????±?????????????´¢
        if(color[u]==WHITE)
            dfs_visit(u);
    for(u=0;u<n;u++)
        printf("%d %d %d\n",u+1,d[u],f[u]);
}

int main(){
    int u,v,k;
    
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            M[i][j]=0;
    
    for(int i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(int j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }
    
    dfs();
}

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

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

    int64_t ans = 0;
    int p = 0;
    while (n--) {
        int a; cin >> a;

        if (a < p) {
            ans += p - a;
            a += p - a;
        }

        p = a;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);

	double ans = 0;
	for(int i = 1; i <= n; i++) ans += i % 2;
	printf("%.12lf\n", ans / n);
	return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N;
int arr[MAXN];
int p[MAXN];
int csum[2*MAXN];

bool good (int cc)
{
    for (int i = 0; i < N; i++)
    {
        if (arr[i] >= cc)
            p[i] = 1;
        else
            p[i] = -1;
    }
    for (int i = 0; i < 2 * MAXN; i++)
        csum[i] = 0;

    int cs = MAXN;
    csum[cs] = 1;
    int ctot = 1;
    ll res = 0;
    for (int i = 0; i < N; i++)
    {
        if (p[i] == -1)
        {
            ctot -= csum[cs];
            cs--;
        }
        else
        {
            ctot += csum[cs+1];
            cs++;
        }
        res += ctot;
        csum[cs]++;
        ctot++;
    }
    //cout << cc << " " << res << "\n";
    return res * 2 >= (N * ((ll) N + 1)) / 2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> arr[i];

    int lo = 0, hi = 1e9;
    while (lo < hi)
    {
        int mid = (lo + hi + 1) / 2;
        if (good (mid))
            lo = mid;
        else
            hi = mid - 1;
    }
    cout << lo << "\n";
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
///////////////////////

string s;

void solve(){
	cin >> s;
	int n = sz(s);
	int cnt = n - 1;
	string s2;
	rep(i, 0, n){
		if(sz(s2)) s2 += "?";
		s2 += s[i];
	}
	s = s2;
	ll ans = 0;
	rep(mask, 0, (1<<cnt)){
		ll sum = 0;
		ll cur = 0;
		int b = 0;
		rep(i, 0, sz(s)){
			if(s[i] == '?'){
				if((1<<b)&mask){
					sum += cur;
					cur = 0;
				}
				++b;
			}else{
				cur = cur * 10 + s[i] - '0';
			}
		}
		ans += sum + cur;
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

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

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;}

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;;
int n,m;
vi a;
ll ans=0;
int mod=1e9+7;
int main( ){
    cin>>n>>m;
    a.resize(m);
    rep(i,m)cin>>a[i];
    vi dp(n+1,0);
    rep(i,m)dp[a[i]]=-1;
    dp[0]=1;
    for(int i=0;i<n;i++){
        if(dp[i]==-1)continue;
        for(int j=1;j<=2;j++){
            if(i+j<=n&&dp[i+j]!=-1){
                dp[i+j]+=dp[i];
                dp[i+j]%=mod;
                if(dp[i+j]<0)dp[i+j]+=mod;
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
typedef long long ll;



int main() {
    int N, T, A; cin >> N >> T >> A;
    vector<int> H(N);
    for(int &h:H) cin >> h;
    
    vector<double> AVE(N);
    for(int i=0; i<N; i++){
        AVE[i] = T - H[i]*0.006;
    }
    
    int ans = 0;
    double mn = 10000000;
    for(int i=0; i<N; i++){
        if(abs(AVE[i] - A) < mn){
            mn = abs(AVE[i] - A);
            ans = i;
        }
    }
    cout << ans + 1 << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    ll dp[100000][3], pt[100000][3];
    
    cin >> N;
    for(int i=0;i<N;i++){
        int a,b,c;
        cin >> a >> b >> c;
        pt[i][0] = a;
        pt[i][1] = b;
        pt[i][2] = c;
    }

    for(int j=0;j<3;j++) dp[0][j] = pt[0][j];
    for(int i=1;i<N;i++){
        for(int j=0;j<3;j++){
            dp[i][j] = pt[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
        }
    }

    cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(ll i=0;i<(n);++i)
using vertex = struct vertex {ll to,cost;vertex(ll to,ll cost):to(to),cost(cost){}};
using AdjList = vector<vector<vertex>>;
using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}};
using Edges = vector<edge>;

vector<ll> Dijkstra(AdjList&adj,ll N,ll S){
  vector<ll> dist(N,(1LL<<60));
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>> ,greater<>> que;
  dist[S]=0LL;
  que.emplace(dist[S],S);
  while(!que.empty()){
    ll cost,from;
    tie(cost,from) = que.top();
    que.pop();
    if(dist[from]<cost)continue;
    for(const auto& v:adj[from]){
      if( chmin(dist[v.to],dist[from]+v.cost) )
        que.emplace(dist[v.to],v.to);
    }
  }
  return dist;
}

main(){

  ll n,m,s,t;
  cin>>n>>m>>s>>t;
  s--;t--;
  AdjList A(n),B(n);
  rep(i,m){
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    u--;v--;
    A[u].emplace_back(v,a);
    A[v].emplace_back(u,a);
    B[u].emplace_back(v,b);
    B[v].emplace_back(u,b);
  }
  auto froms=Dijkstra(A,n,s);
  auto fromt=Dijkstra(B,n,t);

  vector<ll> cost(n);
  cost[n-1]=froms[n-1]+fromt[n-1];
  for(ll i=n-2;i>=0;--i){
    cost[i]=froms[i]+fromt[i];
    chmin(cost[i],cost[i+1]);
  }
  for(const auto& ans:cost){
    cout<<(ll)(1e15-ans)<<endl;
  }

}

Measured memory_bytes: 19012
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;cin>>s;
  	if(s=="KIHBR"||s=="AKIHBR"||s=="AKIHABR"||s=="AKIHBAR"||s=="AKIHBRA"||
      s=="AKIHABAR"||s=="AKIHABRA"||s=="AKIHBARA"||s=="AKIHABARA"||
      s=="KIHABR"||s=="KIHABAR"||s=="KIHABRA"||s=="KIHABARA"||s=="KIHBAR"||
      s=="KIHBRA"||s=="KIHBARA") cout<<"YES";
  	else cout<<"NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int b[45];
int N;
int A[MAXN],t;
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {read(A[i]);t ^= A[i];}
    for(int i = 1 ; i <= N ; ++i) {
	int a = (A[i] - 1) ^ A[i];
	for(int j = 30 ; j >= 0 ; --j) {
	    if(a >> j & 1) {b[j] = a;break;}
	}
    }
    int cnt = 0;
    for(int i = 30 ; i >= 0 ; --i) {
	if(t >> i & 1) {
	    if(b[i]) t ^= b[i];
	    else {puts("-1");return;}
	    ++cnt;
	}
    }
    out(cnt);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;
	int ans=1;
	cin >>n>>k;
	rep(i,n){
		if(ans <k){
			ans*=2;
		}else{
			ans+=k;
		}
		clog<<ans<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int LL;
vector<pair<int,int> > v1;
int t[200005];

int main(){
	int n;
	int a,b,c;
	int i,j,k;
	int m=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
		if(t[m]<t[i])m=i;
	}
	a=-1,c=0;
	for(i=0;i<n;i++){
		if(i==m)continue;
		if(t[i]>t[m]/2)b=t[m]-t[i];
		else b=t[i];
		if(b>=a)a=b,c=i;
	}
	cout<<t[m]<<" "<<t[c]<<endl;
	return 0;
}
	


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define PB push_back
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
namespace DSU {
	int fa[N],sz[N];
	void init(int n) { for(int i=1;i<=n;++i) fa[i]=i,sz[i]=1; }
	int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
	int siz(int x) { return sz[find(x)]; }
	void un(int x,int y) {
		int fx=find(x),fy=find(y);
		if(fx==fy) return;
		sz[fy]+=sz[fx],fa[fx]=fy;
	}
}

vector<int> G[N],Q[N];
int fa[N],son[N],sf[N],n;
int mx[N],ans[N],sub[N];

void dfs1(int u,int last) {
	fa[u]=last,mx[u]=max(mx[last],last);
	sf[u]=son[mx[u]];
	for(int i=0;i<G[u].size();++i) {
		int v=G[u][i]; if(v==last) continue;
		son[u]=v,dfs1(v,u);
	}
}

void dfs2(int u,int last) {
	if(last) ans[u]+=ans[mx[u]]-sub[son[mx[u]]]+1;
	for(int i=0;i<G[u].size();++i) {
		int v=G[u][i]; if(v==last) continue;
		son[u]=v,dfs2(v,u);
	}
}
		
int main() {
	rd(n); DSU::init(n);
	for(int i=1,x,y;i<n;++i) rd(x),rd(y),G[x].PB(y),G[y].PB(x);
	dfs1(1,0);
//	for(int i=1;i<=n;++i) printf("%d ",sf[i]); puts("");
	for(int i=2;i<=n;++i) Q[mx[i]].PB(i);
	for(int i=1;i<=n;++i) {
		for(int j=0;j<Q[i].size();++j) {
			int u=Q[i][j];
			if(u<i) ans[u]=DSU::siz(u)-1;
			else {
				if(sf[u]!=u) ans[u]+=DSU::siz(sf[u]);
				for(int k=0;k<G[u].size();++k)
					if(G[u][k]!=fa[u]&&G[u][k]<i) {
						sub[G[u][k]]=DSU::siz(G[u][k]);
						ans[u]+=sub[G[u][k]];
					}
			}
		}
		for(int j=0;j<G[i].size();++j)
			if(G[i][j]<i) DSU::un(i,G[i][j]);
	}
//	for(int i=1;i<=n;++i) printf("%d ",ans[i]); puts("");
//	for(int i=1;i<=n;++i) printf("%d ",sub[i]); puts("");
	dfs2(1,0);
	for(int i=2;i<=n;++i) printf("%d ",ans[i]);
	return 0;
}

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

using namespace std;

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double dx = abs(x1 - x2);
    double dy = abs(y1 - y2);
    cout << fixed << setprecision(10);
    cout << sqrt(dx * dx + dy * dy) << endl;
    return 0;
}



Measured memory_bytes: 3284
// use proconio::marker::Chars;
use proconio::{fastout, input};
// use std::cmp::{max, min};

struct UnionFind {
    size: usize,
    pos: Vec<isize>,
}

impl UnionFind {
    /// UnionFindを作る関数
    fn new(n: usize) -> Self {
        let size = n;
        let pos = vec![-1; n + 1];
        UnionFind { size, pos }
    }

    /// rootを探す関数
    fn find(&mut self, x: usize) -> usize {
        if self.pos[x] < 0 {
            x
        } else {
            let v = self.pos[x] as usize;
            self.pos[x] = self.find(v) as isize;
            self.pos[x] as usize
        }
    }

    /// xとyの木を結合する関数
    fn unite(&mut self, x: usize, y: usize) -> Result<(), ()> {
        let mut x = self.find(x);
        let mut y = self.find(y);

        // x, y共にrootが設定済みで尚且つ
        // rootが同じ時
        if x == y {
            return Err(());
        }
        if self.pos[x] > self.pos[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.pos[x] += self.pos[y];
        self.pos[y] = x as isize;

        Ok(())
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn size(&mut self, x: usize) -> usize {
        let x = self.find(x);
        -self.pos[x] as usize
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize
    };

    let mut uf = UnionFind::new(n);

    for _ in 0..m {
        input! {
            a: usize,
            b: usize
        }

        uf.unite(a, b);
    }

    let mut result = 0;
    for i in 2..=n {
        if !uf.same(1, i) {
            uf.unite(1, i);
            result += 1;
        }
    }

    println!("{}", result);
}


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

const long long MOD = 1000000007;

struct mint {
  long long x;
  mint(long long x = 0) :x((x%MOD + MOD) % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main(){
  int n, a, b; cin >> n >> a >> b;
  mint x = 2;
  mint tot = x.pow(n);

  mint A = 1;
  rep(i, a) {
    A *= (n - i);
    A /= i + 1;
  }

  mint B = 1;
  rep(i, b) {
    B *= (n - i);
    B /= i + 1;
  }

  cout << (tot - A - B).x - 1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>  
#include<set>
#include<iterator>
#include<list>
#include<utility>
#include<cstdlib>
#include<queue>
#include<stack>
#include<bitset>
//#include<bits/stdc++.h>
#define PI  2*acos(0.0)
#define pb push_back

       
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;



int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);


ll n,ans;
cin>>n;
if(n==0)
{
	ans=1;
}
else
{
	ans=0;
}

cout<<ans<<"\n";





	
	
	return 0;
	
	
	       /***Israil Hosen
	            Computer Science & Engineering
	         University Of Rajshahi.
	         ***/
	
	
	
}


Measured memory_bytes: 3196
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <stack>
#define MX 1000005
#define INF 1000000005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct UF
{
	int par[MX],rank[MX];
	
	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			rank[i]=0;
		}
	}
	void rem(int i)
	{
		par[i]=i;
		rank[i]=0;
	}
	int find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y])
		{
			par[x]=y;
		}
		else
		{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf;
vector <int> vec[MX];
vector <P> query[MX];
int id[MX];
bool use[MX];
int dp[MX];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int p,q,c;
		scanf("%d %d %d",&p,&q,&c);p--,q--,c--;
		query[c].push_back(P(p,q));
	}
	int sz=n;
	for(int i=0;i<MX;i++)
	{
		if(query[i].empty()) continue;
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			uf.rem(p.first);
			uf.rem(p.second);
			id[p.first]=id[p.second]=-1;
			use[p.first]=use[p.second]=false;
		}
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			uf.unite(p.first,p.second);
		}
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			if(!use[p.first])
			{
				use[p.first]=true;
				int r=uf.find(p.first);
				if(id[r]==-1) id[r]=sz++;
				//printf("%d %d: %d\n",r,id[r],p.first);
				vec[p.first].push_back(id[r]);
				vec[id[r]].push_back(p.first);
			}
			if(!use[p.second])
			{
				use[p.second]=true;
				int r=uf.find(p.second);
				if(id[r]==-1) id[r]=sz++;
				//printf("%d %d: %d\n",r,id[r],p.second);
				vec[p.second].push_back(id[r]);
				vec[id[r]].push_back(p.second);
			}
		}
	}
	queue <int> que;
	que.push(0);
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	while(!que.empty())
	{
		int v=que.front();que.pop();
		for(int i=0;i<vec[v].size();i++)
		{
			int to=vec[v][i];
			if(dp[to]==-1)
			{
				dp[to]=dp[v]+1;
				que.push(to);
			}
		}
	}
	if(dp[n-1]==-1) puts("-1");
	else printf("%d\n",dp[n-1]/2);
	return 0;
}


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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[1],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[5];
int l[3];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s[222][22];
//priority_queue<long long,vector<long long>,greater<long long> > q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}



int main()
{
    scanf("%d %d %d",&a,&b,&c);
    for(int t=1;t<=a;t++)
    {
        scanf("%d",&e);
        if(e<=b) n++;
        else if(e<=c) m++;
        else k++;
    }
    printf("%d",min(n,min(m,k)));
}





Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9 + 7;

ll guki(ll a){
  if (a % 2 == 0)
    return true;
  else
    return false;
}

ll count(ll a){
  int cnt = 0;
  while(true){
    cnt++;
    a = a / 2;
    if(a%2 != 0) return cnt;
  }
}

int main(){
  ll n;
  cin >> n;

  vll A;
  rep(i, 0, n){
    ll a;
    cin >> a;
    if (guki(a)){
      A.pb(a);
    }
  }
  ll ans = 0;

  rep(i,0,sz(A)){
    ans += count(A[i]);
  }

  print(ans);



  return 0;
}


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

const double PI=acos(-1.0);
#define ll long long
int main()
{

	
	 ll i,j,k;
	 ll n;

	cin>>n;
  	ll a[n];
    ll sum=1,sum2=1000000000000000000;
	
	for ( i = 0,j = 0; i < n; ++i)	
	{
		cin>>a[i];
		if(a[i]==0)j=1;
		
	}
	if(j==0){
	
	sort(a,a+n);
	for ( i = n-1,k=0; i > -1; --i)
	{
		
		if(a[i]<=(sum2/sum))
		{
			sum*=a[i];				
		}
		else {k=1;break;}
	}

	if(k!=1){
		ll sum3=sum;
		cout<<sum3<<endl;
	}
	else cout<<"-1\n";
	
	
	}
	else cout<<"0\n";
	return 0;
}

Measured memory_bytes: 4396
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;



ll n,h[100010];
ll dp[100010];
bool dpf[100010];

int main(){
    scanf("%lld",&n);
    for(int i=0;i<n;i++)scanf("%lld",&h[i]);
    dp[0]=0;
    for(int i=0;i<n;i++){
        if(dpf[i+1])dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        else dp[i+1]=dp[i]+abs(h[i]-h[i+1]);
        if(dpf[i+2])dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
        else dp[i+2]=dp[i]+abs(h[i]-h[i+2]);
        dpf[i+1]=true;
        dpf[i+2]=true;
        
    }
    printf("%lld\n",dp[n-1]);
    
}


Measured memory_bytes: 1920
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>
#include<set>

using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;
	a += b;
	int x = stoi(a);
	for (int i = 1; i <= 1000; i++) {
		if (x == i * i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int d, n;
  cin >> d >> n;

  if(n==100) n++;
  if(d==0) cout << n << endl;
  if(d==1) cout << 100*n << endl;
  if(d==2) cout << 10000*n << endl;
}

Measured memory_bytes: 3660
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	String S=sc.next();

    	if(S.matches("^YAKI.*")) {
    		System.out.println("Yes");
    	}else {
    		System.out.println("No");
    	}


    }
}



Measured memory_bytes: 23764
// A - Duplex Printing
// https://atcoder.jp/contests/abc157/tasks/abc157_a
#include <iostream>
#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;
const ll mxsize = 3e5 + 5;
const ll linf = 1e9;
const long double inf = 10000000000.0;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1e9 + 9;
#define clr(x) memset(x , 0 , sizeof(x));
 
/******************************************** CODE STARTS FROM HERE *************************************************/ 

int main()
{
  fastIO;
  int n;
  cin >> n;
  if(n % 2 == 0) cout << n / 2 << endl;
  else cout << n / 2 + 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;

ll n,m,x,y,k,num[110],h,dp[25000],cnt,d2[25000],ans;

int main()
{
	ll i,j;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&num[i]);
	}
	sort(num+1,num+n+1);
	dp[0]=d2[0]=1;
	for(i=1;num[i]<k&&i<=n;i++)
	{
		num[i]=k-num[i];
		for(j=3000;j>=num[i];j--)
		{
			dp[j]+=dp[j-num[i]];
		}
	}
	for(;num[i]==k&&i<=n;i++) cnt++;
	for(;i<=n;i++)
	{
		num[i]-=k;
		for(j=3000;j>=num[i];j--)
		{
			d2[j]+=d2[j-num[i]];
		}
	}
	for(i=0;i<=3000;i++)
	{
		ans+=dp[i]*d2[i]*(1ll << cnt);
	}
	cout<<ans-1;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 1000000000000000000
ll n,a,b;
int main(void){
    cin>>n>>a>>b;
    if((b-a)%2==0)cout<<(b-a)/2<<endl;
    else cout<<min(a+(b-a-1LL)/2LL,n-b+1+(b-a-1LL)/2LL)<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, C = LI()
K = int(input())

for k in range(K):
    if A < B:
        C *= 2
    else:
        B *= 2

if A < B and B < C:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10924
def countup(map, index, w)
    return if index < 0 || map.length <= index || map[index] != 1
    map[index] = 2
    if index % w != 0
        countup(map, index-1, w)
        countup(map, index-w-1, w)
        countup(map, index+w-1, w)
    end
    countup(map, index-w, w)
    countup(map, index+w, w)
    if index % w != w-1
        countup(map, index+1, w)
        countup(map, index-w+1, w)
        countup(map, index+w+1, w)
    end
end

while true do
    w, h = gets.split(' ').map(&:to_i)
    break if w == 0 && h == 0
    break unless h
    map = []
    h.times {
        map.push(gets.split(' ').map(&:to_i))
    }
    map_flat = map.flatten
    
    
    count = 0
    while true do
        break unless map_flat.include?(1)
        countup(map_flat, map_flat.index(1), w)
        map_flat.map{ |i| i == 2 ? 0 : i }
        count += 1
    end
    p count
end

Measured memory_bytes: 15476
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	string s; cin >> s;
	int k(0), u(0), p(0), c(0);
	rep(i, 0, s.size()) {
		if (s[i] == 'K')k++;
		else if (s[i] == 'U')u++;
		else if (s[i] == 'P')p++;
		else if (s[i] == 'C')c++;
	}
	cout << min(min(k, u), min(p, c)) << endl;
	return 0;
}

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

int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long max;
  max = a * c;
  if(max < (b * d))max = (b * d);
  if(max < (a * d))max = (a * d);
  if(max < (b * c))max = (b * c);
  cout << max << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1<<28;
 
int main() {
    int W; cin >> W;
    vector<int> a(W);
    for(int i = 0; i < W; ++i) cin >> a[i];
    vector<int> L(W+1), R(W+1);
    L[0] = -1;
    for(int i = 0; i < W; ++i) {
        L[i+1] = L[i] - 1;
        if(a[i] == 0){
            L[i+1] = INF;
        }else if(a[i] < 0){
            L[i+1] = min(L[i+1], -a[i]-1);
        }
    }
    R[W] = -1;
    for(int i = W-1; i >= 0; --i) {
        R[i] = R[i+1] - 1;
        if(a[i] == 0){
            R[i] = INF;
        }else if(a[i] < 0){
            R[i] = min(R[i], -a[i]-1);
        }
    }
    int res = 0;
    for(int i = 0; i < W; ++i) {
        if(a[i] > 0); else continue;
        int t = max(L[i+1], R[i]);
        if(t < 0) continue;
        res += min(a[i], t+1);
    }
    cout << res << endl;
    return 0;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec v;
    rep (i, 10)
        rep (j, 10)
            v.pb(i * 4 + j * 7);
    if (n >= 28)
        print("Yes");
    else {
        repall (i, v)
            if (i == n) {
                print("Yes");
                return 0;
            }
        print("No");
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  bool flag = false;
  for (int i = 1; i <= 9; ++i)
    for (int j = 1; j <= 9; ++j)
      if (i * j == N)
        flag = true;
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

typedef long long ll;
const int MOD = 1000000007;

int n, k, ans;
vector<int> fac, dp;

inline int pwr(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = (ll)c * a % MOD;
        b >>= 1; a = (ll)a * a % MOD;
    }
    return c;
}
inline void add(int &x, int a) {
    x = (x + a >= MOD) ? x + a - MOD : x + a;
}
inline void sub(int &x, int a) {
    x = (x < a) ? x - a + MOD : x - a;
}

int main(void) {
    cin >> n >> k;
    int m = sqrt(n);
    for (int i = 1; i <= m; i++)
        if (n % i == 0) {
            fac.push_back(i);
            fac.push_back(n / i);
        }
    sort(fac.begin(), fac.end());
    fac.erase(unique(fac.begin(), fac.end()), fac.end());
    dp.resize(fac.size());
    for (int i = 0; i < fac.size(); i++) {
        dp[i] = pwr(k, (fac[i] + 1) / 2);
        for (int j = 0; j < i; j++)
            if (fac[i] % fac[j] == 0)
                sub(dp[i], dp[j]);
        if (fac[i] & 1) add(ans, (ll)dp[i] * fac[i] % MOD);
        else add(ans, (ll)dp[i] * fac[i] / 2 % MOD);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//Exactly N points

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    int i;
    for(i=0;(1+i)*i/2<n;i++){}
    vector<int>ans;
    for(;n>0;){
        if(n>=i){
            n-=i;
            ans.pb(i);
            i--;
        }else{
            i--;
            continue;
        }
    }
    rep(i,0,ans.size())cout<<ans[i]<<nnn;
    return 0;
}

Measured memory_bytes: 3728
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][8];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    if (W == 1) {cout << 1 << endl; return 0;}
    dp[0][0] = 1;
    rep(i, H) {
        rep(bit, (1 << (W - 1))) {
            bool ok = true;
            rep(j, W - 1) if ((bit & (1 << j)) && (bit & (1 << (j + 1)))) ok = false;
            if(!ok) continue;
            //cout << bitset<4>(bit) << endl;
            rep(j, W) {
                if (bit & (1 << j)) {
                    dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
                    j++;
                } else {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
                }
            }
        }
    }
    // rep(i, H + 1) {
    //     rep(j, W) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[H][K - 1] << endl;

    return 0;
}
//  o x
// | | | 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	A,B = inputMap()

	if B == 1:
		print(0)
		sys.exit()

	ans = 0
	to = 0
	flg = False
	while True:
		ans += 1
		if flg == False:
			to += A
			flg = True
		else:
			to = (to-1) + A

		if to >= B:
			break

	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep2(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
//const ll mod = 1e9+7;
int gcd(int a, int b){if(a<b) swap(a,b); if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

ll N, M, K, H, W, L, R;

int main(){
  const ll mod = 2019;
  cin >> L >> R;
  if( L+mod <= R ) {cout << 0 << endl; return 0;}
  L %= mod; R %= mod;
  ll ans=1e15;
  for(int i=L; i<=R-1; i++){
    for(int j=i+1; j<=R; j++){
      ans = min(ans, (i*j)%mod);
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

//頂点aから頂点bまで向かうのにかかるコスト（距離）
//ただし、道が1本道の場合のみ
int cost(int a, int b){
    int c = fabs(b - a);
    return c;
}

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;
    vector<vector<int>> graph(N, vector<int>(N, 0));
    rep(i, N){
        rep(j, N){
            graph[i][j] = min(cost(i, j), cost(i, X) + cost(j, Y) + 1);
        }
    }
    
    vector<int> cnt(N);
    rep(i, N){
        for(int j = i; j < N; j++){
            cnt[graph[i][j]]++;
        }
    }
    for(int i = 1; i < N; i++) cout << cnt[i] << endl;
    return 0;
}

Measured memory_bytes: 19284
import java.util.*;

public class Main {

	public static void main(
			String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		boolean[][] map = new boolean[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				map[i][j] = sc.nextInt() % 2 == 1;
			}
		}
		ArrayList list = new ArrayList();
		// 一筆書き
		int cnt = 0;
		while (cnt < h * w) {
			int[] now = getPosition(cnt, w);
			if (map[now[1] - 1][now[0] - 1]) {
				int[] next = getPosition(cnt + 1, w);
				if (next[1] > h) {
					break;
				}
				list.add(now[1] + " " + now[0] + " " + next[1] + " " + next[0]);
				map[now[1] - 1][now[0] - 1] = !map[now[1] - 1][now[0] - 1];
				map[next[1] - 1][next[0] - 1] = !map[next[1] - 1][next[0] - 1];
			}
			cnt++;
		}
		System.out.println(list.size());
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
	}

	static int[] getPosition(
			int cnt,
			int w) {
		int y = cnt / w + 1;
		int x = (y % 2 == 0 ? w - cnt % w : cnt % w + 1);
		int[] xy = {
			x,
			y };
		return xy;
	}
}


Measured memory_bytes: 96232