akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            String[] values = line.split(" ");
            int n = Integer.parseInt(values[0]);
            int m = Integer.parseInt(values[1]);
            if (n == 0 && m == 0) {
                break;
            }
            boolean[] used = new boolean[n];
            int p = -1;
            for (int i = 0; i < n - 1; i++) {
                for (int j = 0; j < m; j++) {
                    while (true) {
                        p++;
                        if (p >= n) {
                            p = 0;
                        }
                        if (!used[p]) {
                            break;
                        }
                    }
                }
                used[p] = true;
            }
            for (int i = 0; i < n; i++) {
                if (!used[i]) {
                    out.println(i + 1);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 9612
N = int(input())
S1 = input()
S2 = input()
r = 1
s = 0
for i in range(N):
  p = s
  if s == 0:
    if S1[i] == S2[i]:
      r = r*3%1000000007
      s = 1
    else:
      r = r*6%1000000007
      s = 2
  elif s == 1:
    if S1[i] == S2[i]:
      r = r*2%1000000007
      s = 1
    else:
      r = r*2%1000000007
      s = 2
  elif s == 2:
    s = 3
  elif s == 3:
    if S1[i] == S2[i]:
      r = r*1%1000000007
      s = 1
    else:
      r = r*3%1000000007
      s = 2
  #print(S1[i], S2[i], p, s, r)
print(r)


Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<string>
using namespace std;
#define N (1<<15)+10
#define inf 0x3f3f3f3f
int t[105][105],d[105],vis[105],mp[205][205],num[15][15];
int n,m;
int spfa(int s)
{
	int temp,i;
    for(i=0;i<=9;i++)
        d[i]=inf,vis[i]=0;
    d[s]=0;
    queue <int> p;
    p.push(s);
    while(!p.empty())
	{
		temp=p.front();
		vis[temp]=0;
		p.pop();
		for(i=0;i<=9;i++)
		{
			if(d[i]>d[temp]+num[temp][i])
			{
				d[i]=d[temp]+num[temp][i];
			if(!vis[i])
			{
				p.push(i);
				vis[i]=1;
			}
			}
		}
	}
	return d[1];
}
int main()
{
    int i,j,a,b,c,sum;
    while(cin>>n>>m)
    {
        sum=0;
	//	if(!n&&!m) break;
        for(i=0;i<=9;i++)
            for(j=0;j<=9;j++)
                cin>>num[i][j];
        for(i=1;i<=n;i++)
            for(j=1;j<=m;j++)
            {
                cin>>mp[i][j];
                if(mp[i][j]!=-1&&mp[i][j]!=1)
                    sum+=spfa(mp[i][j]);
            }
        cout<<sum<<endl;
    }
	return 0;

}

Measured memory_bytes: 384
import sys,collections
input = sys.stdin.readline

N,Q = list(map(int,input().split()))
road = [[] for i in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    road[a].append(b)
    road[b].append(a)
point = [0]*(N+1)

for _ in range(Q):
    p,x = map(int,input().split())
    point[p] += x

q = collections.deque([1])
visit = [0]*(N+1)
visit[1]=1

while q:
    now = q.pop()
    for i in road[now]:
        if visit[i] == 0:
            q.append(i)
            point[i] += point[now]
            visit[i]=1

print(*point[1:])


Measured memory_bytes: 118116
/*  -*- coding: utf-8 -*-
 *
 * 2917.cc: Pray
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int h, w, x, y;
  scanf("%d%d%d%d", &h, &w, &x, &y);

  if (((h * w) & 1) && ((x + y) & 1)) puts("No");
  else puts("Yes");
  return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#define INF 1000000000
using namespace std;
int n,mp[100010],dp[100010];
bool visited[100010];

int mk_mp(int ima){
  if(visited[ima]||mp[ima]==-INF) return -INF;
  visited[ima]=1;
  if(mp[ima]!=0) mp[ima]+=mk_mp(ima+mp[ima]);
  if(mp[ima]<-10000000) mp[ima]=-INF;
  visited[ima]=0;
  return mp[ima];
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++)cin>>mp[i];
  for(int i=1;i<n;i++)mp[i]=mk_mp(i),dp[i]=-1;
  
  int cnt=0;
  while(dp[n-1]==-1){
    cnt++;
    for(int i=0;i<n;i++)
      if(dp[i]==cnt-1)
	for(int j=1;j<=6;j++){
	  int nx=i+j;
	  while(nx>=0&&mp[nx]!=0)nx+=mp[nx];
	  if(nx>=0&&dp[nx]==-1)dp[nx]=cnt;
	}
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long A[100010];
long long B[100010];
int main(){
    int N;
    cin >> N;
    rep(i,N+1){
        cin >> A[i]; 
    }
    rep(i,N){
        cin >> B[i];
    }
    long long cnt = 0;
    for(int i=N-1;i>=0;i--){
        if(B[i] >= A[i+1]){
            B[i] -= A[i+1];
            cnt += A[i+1];
            A[i+1] = 0;
            if(B[i] >= A[i]){
                B[i] -= A[i];
                cnt += A[i];
                A[i] = 0;
            }else{
                A[i] -= B[i];
                cnt += B[i];
                B[i] = 0;
            }
        }else{
            A[i+1] -= B[i];
            cnt += B[i];
            B[i] = 0;
        }
        //cout << cnt << "a\n";
    }
    cout << cnt << endl;

}

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

using namespace std;

const int N = 2e5 + 10;

int n, a[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 2; i++) {
  	scanf("%d", &a[i]);
  }
  sort(a + 1, a + n * 2 + 1);
  int res = 0;
  for (int i = 1; i <= n * 2; i += 2) {
  	res += a[i];
  }
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,m,b[N],fl[N];long double a[N];long long k;
int u[N];
void work(int a[],int b[])
{
	int ans[N];
	for (int i=1;i<n;i++)
		ans[i]=a[b[i]];
	for (int i=1;i<n;i++)
		a[i]=ans[i];
}
void work(int u[],long long k)
{
	int ans[N];
	for (int i=1;i<n;i++)
		ans[i]=i;
	for (;k;k>>=1)
	{
		if (k&1) work(ans,u);
		work(u,u);
	}
	for (int i=1;i<n;i++)
		u[i]=ans[i];
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%Lf",&a[i]);
	
	scanf("%d%lld",&m,&k);
	for (int i=1;i<=m;i++)
		scanf("%d",&b[i]);
	for (int i=1;i<n;i++)
		u[i]=i;
	for (int i=1;i<=m;i++)
		swap(u[b[i]-1],u[b[i]]);
	work(u,k);
	double now=a[1];
	for (int i=1;i<=n;i++)
	{
		printf("%.9f\n",now);
		now+=a[u[i]+1]-a[u[i]];
	}
}

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

int main(int argc, char *argv[]) {
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for (int i = 0; i < n; ++i) {
    cin >> l[i];
  }

  int cnt = 1;
  int d = 0;
  for (int i = 0; i < n; ++i) {
    d = d + l[i];
    if (d > x) {
      break;
    }
    cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&a!=c)cout<<"Yes"<<endl;
  else if(a==c&&a!=b)cout<<"Yes"<<endl;
  else if(b==c&&b!=a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
  int N,K,Z=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    Z+=2*min(a,K-a);
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 256
open System

let n = stdin.ReadLine()
let a = stdin.ReadLine().Split(' ') |> Array.map int

let rec canDiv2 = fun v -> if v % 2 = 1 then 0 else (1 + canDiv2(v / 2))

a
|> Array.map canDiv2
|> Array.min
|> printfn "%d"

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

typedef long long ll;

const int Maxn = 500005;
const int Maxm = 1 << 20;
const int mod = 1000000007;

int n;
int a[Maxn];
int add1[Maxn], add2[Maxn];
vector <int> V[Maxm];
int my[Maxn];
int res;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        a[i] ^= a[i - 1];
        V[a[i]].push_back(i);
    }
    for (int i = 1; i < Maxm; i++) if (!V[i].empty())
        add2[V[i][0]]++;
    int zers = 0;
    for (int i = 1; i <= n; i++)
        if (a[i] == 0) zers++;
        else {
            my[i] = (ll(zers) * add1[i] % mod + ll(add2[i])) % mod;
            int ind = upper_bound(V[a[i]].begin(), V[a[i]].end(), i) - V[a[i]].begin();
            if (ind < V[a[i]].size()) {
                int nxt = V[a[i]][ind];
                add1[nxt] = (ll(add1[nxt]) + ll(add1[i]) + ll(my[i])) % mod;
                add2[nxt] = (ll(add2[nxt]) + ll(add2[i]) - ll(my[i]) * zers % mod + ll(mod)) % mod;
            }
        }
    if (a[n] == 0) {
        int pw = 1;
        for (int i = 1; i < n; i++)
            if (a[i] == 0) pw = pw * 2 % mod;
            else res = (res + my[i]) % mod;
        res = (res + pw) % mod;
    } else res = my[n];
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 42228
#include <bits/stdc++.h>
using namespace std;
int main(){
   long s,c=1e9;
   cin >> s;
   long x=(c-s%c)%c;
   long y=(s+x)/c;
   cout << 0 << ' ' << 0 << ' '<< c << ' '<< 1 << ' '<< x << ' ' << y << endl;
}


Measured memory_bytes: 256
import queue
k = int(input())

q = queue.Queue()
num = 0
for i in range(1,10):
    q.put(i)

while num<k:
    i = q.get()
    l = i%10
    if l!=0:
        q.put(i*10+l-1)
    q.put(i*10+l)
    if l!=9:
        q.put(i*10+l+1)
    num += 1

print(i)


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

arr = [0] * (n+1)

for i in range(1,n+1):
    x = []
    while i % 2 == 0:
        x.append(2)
        i = i // 2
    f = 3
    while f * f <= i:
        if i % f == 0:
            x.append(f)
            i = i // f
        else:
            f += 2
    if i != 1:
        x.append(i)

    for k in range(len(x)):
        arr[x[k]] += 1

ans = 1
for i in range(len(arr)):
    ans *= (arr[i] + 1)
print(ans % (10**9 + 7))


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read(), digits = 0, tmp, ans = 0;
  for (int i = 1; i <= n; i++) {
    tmp = i;
    digits = 0;
    while (tmp > 0) {
      tmp /= 10;
      digits++;
    }
    if (digits & 1)
      ans++;
  }
  print(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<unordered_map>
using namespace std;
int main(){
    unordered_map<string,int> mp;
    int n;cin>>n;
    string s;
    long long res=0;
    for(int i=1;i<=n;i++)
    {
        char C[12];cin>>C;
        sort(C,C+10);
        s=string(C);
        res+=mp[s];
        mp[s]++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 10660
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,D;
  cin >> N >> D;
  D = 2*D + 1;
  if(N%D==0)
  {
    cout << N/D << endl;
  }
  else
  {
    cout << N/D+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}
ll n;
ll arr[1000000];
ll dp[1000000];
ll solve(ll i)
{
    if(i==n-1)
      return 0;
    if(dp[i]!=-1)
       return dp[i];
    ll left=abs(arr[i]-arr[i+1])+solve(i+1);
    ll right=INT32_MAX;
    if(i+2<n)
      right=abs(arr[i]-arr[i+2])+solve(i+2);
    return dp[i]=min(left,right);
}
void pk()
{
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(ll i=0;i<n;i++)
       cin>>arr[i];
    cout<<solve(0);
   
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
    //cin>>t;
    while(t--)
    {
        pk();
    }
} 

Measured memory_bytes: 15296
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    cin >> s;
    vi lw(n);
    vi re(n);

    for(int i=1; i<n; ++i) {
        if(s[i-1]=='W') {
            lw[i] = lw[i-1]+1;
        } else {
            lw[i] = lw[i-1];
        }
    }
    for(int i=n-2; i>=0; --i) {
        if(s[i+1]=='E') {
            re[i]= re[i+1]+1;
        } else {
            re[i]=re[i+1];
        }
    }
    int res = INF;
    rep(i,n) {
        res = min(res, re[i]+lw[i]);
    }
    cout << res << "\n";

}

Measured memory_bytes: 2964
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 行ごとのiterが取れる
    let mut iter = buf.split_whitespace();
    let steps: usize = iter.next().unwrap().parse().unwrap();
    let costs: Vec<i32> = (0..steps)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();
    let mut dp = vec![0; steps];

    for step in 1..steps {
        if step == 1 {
            dp[step] = i32::abs(costs[step - 1] - costs[step]);
            continue;
        }
        let one_step_cost = dp[step - 1] + i32::abs(costs[step - 1] - costs[step]);
        let tow_step_cost = dp[step - 2] + i32::abs(costs[step - 2] - costs[step]);
        dp[step] = if one_step_cost < tow_step_cost {
            one_step_cost
        } else {
            tow_step_cost
        }
    }
    println!("{:?}", dp[steps - 1]);
}

Measured memory_bytes: 4352
A, B, C, D, E, F = map(int, input().split())

max_water = 0
max_sugar = 0
max_con = 0
max_AB = 31
max_CD = 101

for a in range(max_AB):
    for b in range(max_AB):
        water = (100 * A) * a + (100 * B) * b
        if water == 0:
            break

        for c in range(max_CD):
            for d in range(max_CD):
                sugar = C * c + D * d
                if water + sugar > F:
                    break

                con = 100*sugar / (water + sugar)
                if water/100 * E >= sugar and con >= max_con:
                    max_con = con
                    max_water = water
                    max_sugar = sugar
print(str(max_water+max_sugar) + " " + str(max_sugar))


Measured memory_bytes: 3064
#include <stdio.h>
#define ll long long int

int main() {
    int n;
    scanf("%d", &n);
    ll arr[n], max = 1000000000000000000, prod = 1, flag = 0, zero = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &arr[i]);
        if (arr[i] > max) {
            flag = 1;
        }
        prod *= arr[i];
        arr[i] ? max /= arr[i] : zero = 1;
    }
    if (zero) {
        puts("0");
    }
    else {
        flag ? printf("-1\n") : printf("%lld\n", prod);
    }
    return 0;
}


Measured memory_bytes: 2488
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<(w*h)/2.0;
	if(2*x==w && 2*y==h)
	cout<<" "<<"1";
	else
	cout<<" "<<"0";
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    int a[4],b[2];
    rep(i,4) cin >>a[i];
    rep(j,2) cin >>b[j];

    sort(a,a+4,greater<int>());
    sort(b,b+2,greater<int>());

    printf("%d\n", a[0]+a[1]+a[2]+b[0]);
    return 0;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    ll k; cin >> k;
    ll p = k / 50, q = k % 50;
    vector<ll> arr(50, 49 + p);
    cout << 50 << endl;
    for (int i = 0; i < q; i++){
        arr[i] += 1;
    }
    for (int i = q; i < 50; i++){
        arr[i] -= q;
    }
    for (int i = 0; i < 50; i++)
        cout << arr[i] <<  ' ';
    cout << endl;
}


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

const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long b,long long mod){
        bitset<30> bit(b);
        string s = bit.to_string();
        long long ret = 1;
        for (int i = 0;i< s.length(); ++i){
                ret = (ret * ret) % mod;
                if(s[i]-'0') ret = (ret * a) % mod;
        }
        return ret;
}


/*繰り返し二乗法でxのmod逆元を取る*/
long long inverse(long long x,long long mod){
    return modpow(x,mod-2,mod);
}

int n = 200005;
vector<vector<int>> tree(n,vector<int>());
vector<P> dp(n,P(0,0));

P dfs1(int i,int p=-1){
    if(dp[i].first != 0) return dp[i];
    ll sz = 0;
    ll dpi = 1;
    for(int next:tree[i]){
        if(next == p ) continue;
        P now = dfs1(next,i);
        sz += now.first;
        dpi = ((dpi * now.second)%MOD * COM(sz,now.first))%MOD;
    }
    dp[i] = P(sz+1,dpi);
    return dp[i];
}

void dfs2(int i,int p=-1,P gift=P(0LL,0LL)){
    if(p != -1){
        dp[i].first += gift.first;
        dp[i].second = ((dp[i].second * gift.second)%MOD * COM(dp[i].first-1,gift.first))%MOD;
    }
    ll sz = dp[i].first;
    ll dpi = dp[i].second;
    for(int next:tree[i]){
        if(next == p) continue;
        dfs2(next,i,P(sz-dp[next].first,(dpi*inverse((dp[next].second*COM(sz-1,dp[next].first))%MOD,MOD))%MOD));
    }
}

int main(){
    COMinit();
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs1(0);
    dfs2(0);
    rep(i,n) cout << dp[i].second << '\n';
    return 0;
}



Measured memory_bytes: 40436
N = int(input())
S = [input() for i in range(N)]
ans = {}
for s in S:
  ans[s] = ans.get(s, 0) + 1

m = max(ans.items(), key=lambda x: x[1])[1]
a = [s[0] for s in ans.items() if s[1] == m]
print(*sorted(a), sep="\n")

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

using namespace std;
using ll = long long;

int main() {
    int x,n = 0;
    cin >> x >> n;
    if(n == 0){
        cout << x << endl;
        return 0;
    }
    vector<int> v(100);
    for(int i = 0;i < n;i++){
        int tmp = 0;
        cin >> tmp;
        v[tmp] ++;
    }

    for(int i = 0;i < 100;i++){
        if(v[x - i] != 1){
            cout << x - i << endl;
            return 0;
        }
        if(v[x + i] != 1){
            cout << x + i << endl;
            return 0;
        }
    }
    return 0;
}

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

int n;
std::vector<int> data[100005];
int d1[100005], d2[100005];

void dfs(const int pos, const bool turn) {
	int *d;
	if (turn) {
		if (pos == n - 1)
			return;
		d = d1;
	}
	if (!turn) {
		if (pos == 0)
			return;
		d = d2;
	}

	for (size_t i = 0, end = data[pos].size(); i < end; ++i) {
		auto dp = data[pos][i];
		auto *dd = &d[dp];
		if (dp != 0 && dp != n - 1 && *dd == -1) {
			*dd = d[pos] + 1;
			dfs(dp, turn);
		}
	}
}

int main()
{
	std::cin >> n;
	std::fill(d1, d1 + n, -1);
	std::fill(d2, d2 + n, -1);
	d1[0] = 0;
	d2[n - 1] = 0;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		std::cin >> a >> b;
		--a, --b;
		data[a].emplace_back(b);
		data[b].emplace_back(a);
	}

	dfs(0, true);
	dfs(n - 1, false);

	int first = 0;
	for (int i = 0; i < n; ++i)
		if (d1[i] < 0)
			continue;
		else if (d2[i] < 0)
			++first;
		else if (d1[i] <= d2[i])
			++first;

	if (first > n - first)
		std::cout << "Fennec" << std::endl;
	else
		std::cout << "Snuke" << std::endl;
	return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    string s; cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>m;
	if(n==0&&m==0)
	{
		cout<<0;
		return 0;
	}
	cout<<(n-1)*(m-1);	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    long double a,b;
    cin >> a >> b;
    cout << (int)(a/b) << ' ' << (int)(a)%(int)(b) << ' ' << fixed << setprecision(6) << a/b << endl;
}


Measured memory_bytes: 3264
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>
template <class T> class Node {
public:
	Node()
		:parent(NULL), child(NULL)
	{};
	Node* parent;
	Node* child;
	T para;
};
template <class T> class UnionFind {
public:
	void Connect(Node<T>* a, Node<T>* b) {
		Vertex(a)->parent = Vertex(b);
	};
	bool Same(Node<T>* a, Node<T>* b) {
		return Vertex(a) == Vertex(b);
	};
private:
	Node<T>* Vertex(Node<T>* _obj) {
		if (_obj->parent == NULL) {
			return _obj;
		}
		else {
			return _obj->parent = Vertex(_obj->parent);
		}
	};
};
using namespace std;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
#define _CRT_SECURE_NO_WARNINGS
int N,M;
int x[10010], y[10010];
UnionFind<int> UF;
struct L{
	int s, g;
	double cost;
	bool operator < (const L& _l)const{
		return cost < _l.cost;
	};
	bool operator > (const L& _l)const {
		return cost > _l.cost;
	};
	void Set(int _x, int _y, double _c) {
		s = _x;
		g = _y;
		cost = _c;
	}
}loads[10010 * 10010];
double ans = 0;
Node<int> n[10010];

int main() {
	scanf("%d %d", &N , &M);
	for (int i = 0; i < N;i++) {
		scanf("%d %d",&x[i],&y[i]);
	}
	for (int i = 0; i < M; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		loads[i].Set(a, b, (double)sqrt( (double)((x[a] - x[b])*(x[a] - x[b]) + (y[a] - y[b])*(y[a] - y[b])) ) );
	}
	std::sort(loads, &loads[M],std::greater<L>());
	
	for (int i = 0; i < M; i++) {
		if (!UF.Same(&n[loads[i].s], &n[loads[i].g])) {
			UF.Connect(&n[loads[i].s], &n[loads[i].g]);
		}
		else {
			ans += loads[i].cost;
		}
	}
	printf("%lf\n", ans);
	return 0;
}

Measured memory_bytes: 3508
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BDistance solver = new BDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BDistance {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt(), d = in.readInt();
            int ans = 0;
            for (int i = 0; i < n; i++) {
                int x = in.readInt(), y = in.readInt();
                if (distFromOrigin(x, y) <= d)
                    ans++;
            }

            System.out.println(ans);
        }

        double distFromOrigin(int x, int y) {
            return Math.sqrt((long) x * x + (long) y * y);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 36576
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int mxN = 2e5 + 5;
int n, A[mxN], vis[mxN];
ll k;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> A[i];
    int s = 1;
    while (vis[s] < 2) {
        vis[s]++;
        s = A[s];
    }
    ll a = 0, b = 0;
    for (int i = 1; i <= n; i++) {
        if (vis[i] == 1)
            a++;
        else if (vis[i] == 2)
            b++;
    }

    ll moves = (k - a) % b + a;

    if (k < a)
        moves = k;

    s = 1;
    for (ll i = 0; i < moves; i++) {
        s = A[s];
    }
    cout << s;
    /*
        cout << endl;
        cout << moves << endl;
        for (int i = 1; i <= n; i++)
            cout << vis[i] << " ";
        cout << endl;*/
}


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

int main() {
  int N, a;
  int64_t D,x,y,DS,xS,yS;
  a=0;
  cin >> N >> D;
  DS=D*D;
  for(int i=0; i<N; i++){
    cin >> x >> y;
    xS =x*x;
    yS= y*y;
    if (xS + yS <= DS)
      a++;
  }
  cout << a << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define M 998244353
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<double,ll> pll;
#define pb push_back
#define M6 5000009
#define M5 500009
#define pi 3.14159265
ll power(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=(res*x)%M;
        n/=2;
        x=(x*x)%M;
    }
    return res;
}
ll prime[M6];
void sieve(){
    for(int i=2;i<M6;i++) prime[i]=1;
    for(int i=2;i*i<M6;i++){
        if(prime[i]==0) continue;
        for(int j=i*2;j<M6;j+=i) prime[j]=0;
    }
}
ll n,m,A[M5];
int  main()
{   ios_base::sync_with_stdio (0), cin.tie (0);
    //sieve();
    //init();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll tc=1,t=0,i,j,k,l,a,b,c,d;
    //cin>>tc;
    while(t++<tc){
        cin>>k>>l;
        vector<ll> v;
        for(i=l;i>=-1000000 && i>l-k;i--) v.pb(i);
        for(i=l+1;i<=1000000 && i<l+k;i++)  v.pb(i);
        sort(v.begin(),v.end());
        for(auto u:v) cout<<u<<" ";
    }
    return 0;
}

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

int main(){
	int W,a,b;
  cin>>W>>a>>b;
  if(b>=a+W)
    cout<<b-(a+W);
  else if(a>=b+W)
    cout<<a-(b+W);
  else
    cout<<0<<endl;
}

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

using namespace std;

int main(){
int a,b,c,sum[3];
cin>>a>>b>>c;
sum[0]=a*10+b+c;
sum[1]=b*10+a+c;
sum[2]=c*10+b+a;
sort(sum,sum+3);
cout<<sum[2]<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int N, K;
vector<long long> sum;
 
long long calc(int kk, int j){
 return (j == 0) ? sum[min(j+kk, N)-1] : sum[min(j+kk, N)-1] - sum[j-1];
}
 
int main(){
  ios_base::sync_with_stdio(false); 
  cin >> N >> K;
  string s;
  cin >> s;
  N = s.length();
  int c = 1;
  int f = (s[0] == '1');
  long long co = 0;
  for(int i=0; i+1<N; ++i){
    if(s[i] == s[i+1])
       ++c;
    else{
      sum.push_back(c+co);
      co += c;
      c = 1;
    } 
  }
  sum.push_back(c+co);
  N = sum.size();
  long long res = 0;
  if(f){
    for(int i=0; i<N; ++i){
      long long p = (i&1) ? calc(2*K, i) : calc(2*K+1, i);
      res = max(res, p);
    }
  }
  else{
   for(int i=0; i<N; ++i){
     long long p = (i&1) ? calc(2*K+1, i) : calc(2*K, i);
     res = max(res, p);
   }
  }
  cout << res << "\n";
  return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long a, long long b, long long x){
    LL a1 = max(0LL, a-1) / x;
    LL a2 = b / x;

    cout << a2 - a1 + (a == 0LL) << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    solve(a, b, x);
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
namespace FastIO{const char* ln="\n";struct Reader{char buf[1<<20],*s,*t;bool EOF_FLG;Reader():s(buf),t(buf),EOF_FLG(false) {};char gt() {return s==t&&((t=(s=buf)+fread(buf,1,1<<20,stdin))==s)?EOF:(*s++);}Reader& operator>>(char* str) {if(EOF_FLG)return *str=0,*this;while((*str=gt())!=' '&&*str!='\n'&&*str!=EOF)++str;if(*str==EOF)EOF_FLG=true;*str=0;return *this;}template<typename T>Reader&operator>>(T&x) {if(EOF_FLG)return *this;char c=0,d;while(c!=EOF&&(c<'0'||c>'9'))d=c,c=gt();if(c==EOF){EOF_FLG=true;return *this;}else x=0;while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();if(d=='-')x=-x;return *this;}}in;struct Writer{char buf[1<<20],*s,*t;Writer():s(buf),t(buf+(1<<20)){}~Writer(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,1<<20,stdout),*s++=c):(*s++=c);}template<typename T>Writer&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[40],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}Writer&operator<<(const char*s) {while(*s)pt(*s++);return *this;}}out;}using namespace FastIO;
namespace ZDY{
	#define ll long long
	#define db double
	#define sht short
	#define MB template <class T>
	#define Fur(i,x,y) for(int i=x;i<=y;i++)
	#define fur(i,x,y) for(i=x;i<=y;i++)
	#define Fdr(i,x,y) for(int i=x;i>=y;i--)
	#define fdr(i,x,y) for(i=x;i>=y;i--)
	#define clr(x,y) memset(x,y,sizeof(x))
	#define cpy(x,y) memcpy(x,y,sizeof(x))
	#define inf 0x3f3f3f3f
	#define fin(s) freopen(s".in","r",stdin)
	#define fout(s) freopen(s".out","w",stdout)
	#define l2(n) (int(log2(n)))
	#define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
	#define fcin ios::sync_with_stdio(false)
	MB T ABS(T x){return x>0?x:-x;}
	MB T MAX(T x,T y){return x>=y?x:y;}
	MB T MIN(T x,T y){return x<=y?x:y;}
	MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
	void SWAP(int &x,int &y){x^=y;y^=x;x^=y;}
}using namespace ZDY;using namespace std;
#define N 100011
int a[N],n;
int main(){
	in>>n;
	Fur(i,1,n)in>>a[i];
	sort(a+1,a+n+1);
	Fur(i,1,n-1)a[n]-=a[i];
	if(a[n]>=0)printf("No\n");
	else printf("Yes\n");
}

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

using namespace std;

int main() {

	int n;
	cin >> n ;

	vector<long long> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= (i + 1);
	}

	sort(a.begin(), a.end());

	long long ave = a[n / 2];
	long long total1 = 0;
	for (int i = 0; i < n; i++) {
		total1 += abs(a[i] - ave);
	}
	cout << total1 << endl;
}

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

const int MAX = 1000005;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void com_init() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll com(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	int x, y;
	cin >> x >> y;
	com_init();
	int ans = 0;
	if ((x + y) % 3 == 0) {
		int n = (2 * y - x) / 3;
		int m = (2 * x - y) / 3;
		if (n >= 0 && m >= 0) ans = com(n + m, n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27052
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        out.println((x+y/2));
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,D1,D2;
vector<pair<int,int>> NG;

void hoge(int v) {
	for(int a=0;a*a<=v;a++) {
		int b;
		for(b=0;a*a+b*b<v;b++);
		if(a*a+b*b==v) {
			NG.push_back({a,b});
			NG.push_back({a,-b});
			NG.push_back({-a,b});
			NG.push_back({-a,-b});
		}
	}
}

int ok[606][606];

vector<pair<int,int>> D[2];
void dfs(int y,int x,int d) {
	if(ok[y][x]==0) return;
	ok[y][x]=0;
	D[d].push_back({x,y});
	FORR(a,NG) {
		if(x+a.first<0) continue;
		if(x+a.first>2*N) continue;
		if(y+a.second<0) continue;
		if(y+a.second>2*N) continue;
		dfs(y+a.second,x+a.first,d^1);
	}
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>D1>>D2;
	hoge(D1);
	sort(ALL(NG));
	NG.erase(unique(ALL(NG)),NG.end());

	FOR(x,2*N) FOR(y,2*N) ok[y][x]=1;
	vector<pair<int,int>> R;
	
	FOR(y,2*N) FOR(x,2*N) if(ok[y][x]) {
		D[0].clear();
		D[1].clear();
		dfs(y,x,0);
		if(D[0].size()<D[1].size()) swap(D[0],D[1]);
		FORR(d,D[0]) R.push_back(d);
	}
	NG.clear();
	hoge(D2);
	sort(ALL(NG));
	NG.erase(unique(ALL(NG)),NG.end());
	
	FOR(x,2*N) FOR(y,2*N) ok[y][x]=0;
	FORR(r,R) ok[r.first][r.second]=1;
	R.clear();
	FOR(y,2*N) FOR(x,2*N) if(ok[y][x]) {
		D[0].clear();
		D[1].clear();
		dfs(y,x,0);
		if(D[0].size()<D[1].size()) swap(D[0],D[1]);
		FORR(d,D[0]) R.push_back(d);
	}
	
	assert(R.size()>=N*N);
	FOR(i,N*N) cout<<R[i].first<<" "<<R[i].second<<endl;	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 30052
#include <iostream>

using namespace std;

int main(){
    int cnt[4] = {};
    for(int i = 0; i < 3; i++){
        int a, b;
        cin >> a >> b;
        cnt[a - 1]++;
        cnt[b - 1]++;
        if(cnt[a - 1] == 3 || cnt[b - 1] == 3){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 1;
        int a = 0;
        while (ans <= n) {
            ans = ans * 2;
        }
        System.out.println(ans / 2);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////


int main(){
    ll n,m;cin>>n>>m;
    vector<ll>v[n];
    ll col[n];memset(col,-1,sizeof(col));
    rep(i,0,m-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        v[a].pb(b);v[b].pb(a);
    }
    bool flag=false;
    queue<int>q;
    q.push(0);col[0]=0;
    while(!q.empty()){
        int t=q.front();q.pop();
        for(auto x:v[t]){
            if(col[x]==-1){
                col[x]=1-col[t];
                q.push(x);
            }else{
                if(col[x]==col[t]){
                    flag=true;
                    break;
                }
            }
        }
        if(flag)break;
    }
    if(flag){
        cout<<n*(n-1)/2-m<<endl;
    }else{
        ll c=0;rep(i,0,n-1)if(col[i])c++;
        cout<<c*(n-c)-m<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 7168
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N=15;
int arr[N][N];
int num[N];
int main() {
	ll n;cin>>n;
	loop(n,i,0){
		int q;cin>>q;
		num[i]=q;
		loop(q,j,0){
			int x,y;cin>>x>>y;
			if(!y)arr[i][x-1]=-1;
			else arr[i][x-1]=1;
		}
	}
	int all=(1LL<<n);
	ll res=0;
	loop(all,i,0){
		string bin=bitset<N+1>(i).to_string();
		reverse(allv(bin));
		ll cnt=0;
		bool flag=0;
		loop(n,j,0){
			if(bin[j]-'0'){
				cnt++;
				loop(n,k,0){
					if(arr[j][k]==0)continue;
					if((arr[j][k]==1&&bin[k]!='1')||(arr[j][k]==-1&&bin[k]!='0'))
						flag=1;
				}
			}
		}
		if(!flag)res=max(res,cnt);
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 256
#define George_Plover
#include <queue>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 200001
#define MAXM
#define INF
using namespace std;
int n;
map <string,int> h;
string s[MAXN];
int cnt=0;
int main()
{

    cin>>n;
    int maxx=0;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        h[s[i]]+=1;
        maxx=max(maxx,h[s[i]]);
    }
    
    for(int i=1;i<=n;i++)
    {
        if(h[s[i]]==maxx)
        {
            s[++cnt]=s[i];
            h[s[i]]=0;
        }
    }
    
    sort(s+1,s+cnt+1);
    
    for(int i=1;i<=cnt;i++)
    {
        cout<<s[i]<<endl;
    }
    
    return 0;
}


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


int main(){
        int n;
        cin>>n;
        vector<int> h(n);
        for(int i=0;i<n;i++)cin>>h[i];
        vector<int> dp(n,0);
        dp[0] = 0;
        dp[1] = abs(h[1]-h[0]);
        for(int i=2;i<n;i++) dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]) );
        cout<<dp[n-1]<<endl;

        return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

struct Edge {
    int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
    int k = 1;
    rep(i, g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u == p) continue; // 親との辺の場合
        if (k == c) k++; // 親で使用した色の場合
        ans[ei] = k;
        k++;
        dfs(u, ans[ei], v);
    }
}

int main() {
    int N;
    cin >> N;
    g.resize(N);
    ans = vector<int>(N - 1);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back((Edge) {b, i});
        g[b].push_back((Edge) {a, i});
    }

    dfs(0);
    int mx = 0;
    rep(i, N) mx = max(mx, int(g[i].size()));

    cout << mx << endl;
    rep(i, N - 1) {
        cout << ans[i] << endl;
    }
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll MOD = 1e9 + 7;
const int N = 2e5 + 5;

bitset<100005> p;
vi primes;

ll bpow(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

void sieve() {
    p.set();
    for (int i = 2; i < 100005; ++i) {
        if (p[i]) {
            primes.push_back(i);
            for (int j = i + i; j < 100005; j += i) p[j] = 0;
        }
    }
}

ll fac[N], inv[N];

void pre() {
    fac[0] = fac[1] = 1;
    rep(i, 2, N)
        fac[i] = fac[i - 1] * i % MOD;
    rep(i, 0, N)
        inv[i] = bpow(fac[i], MOD - 2);
}

ll combo(ll n, ll k) {
    ll res = 1;
    res = res * fac[n + k - 1] % MOD;
    // cout << "COMBO: " << n << ' ' << k << ' ' << res << '\n';
    res = res * inv[k] % MOD;
    res = res * inv[n - 1] % MOD;

    return res;
}

ll n, m, pf;

int main() {
	cin.tie(0)->sync_with_stdio(0);
    sieve();
    pre();
    cin >> n >> m;
    ll ans = 1;
    for (auto prime : primes) {
        int cnt = 0;
        while (m % prime == 0) {
            ++cnt;
            m /= prime;
        }
        if (!cnt) continue;
        ans = ans * combo(n, cnt) % MOD;
    }
    if (m != 1) ans = ans * n % MOD;
    cout << ans;
}


Measured memory_bytes: 6904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;



int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    
    int cnt = 0;
    int sum;
    for(int a = 0; a<= A; ++a){
        for(int b = 0; b <= B; ++b){
            for(int c = 0; c <= C; ++c){
                sum = 500 * a + 100 * b + 50 * c;
                if(sum == X){
                    ++cnt;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256