akhauriyash/Code-Regression huggingface dataset:
find :: (Ord a) => Int -> a -> [a] -> Int
find _ _ [] = (-1)
find i c (x:xs)
  | c == x = i
  | otherwise = find (i+1) c xs

fstFind :: (Ord a) => a -> [a] -> Int
fstFind c = find 0 c

main = do
  line <- getLine
  let
    len = length line
    idxA = fstFind 'A' line
    idxZ = fstFind 'Z' $ reverse line
    ans = len - idxZ - idxA
  putStrLn $ show ans


Measured memory_bytes: 20988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<double> VD;

int main() {
  int K, N;
  cin >> N >> K;
  VD P(N);
  rep(i, N) {
    double p;
    cin >> p;
    p++;
    p /= 2.0;
    P.at(i) = p;
  }
  double sum = 0.0;
  rep(i, K) { sum += P.at(i); }
  double maxi = sum;
  rep(i, N - K) {
    sum -= P.at(i);
    sum += P.at(K + i);
    maxi = max(maxi, sum);
  }

  cout << fixed;
  cout << setprecision(10) << maxi << endl;
  return 0;
}


Measured memory_bytes: 1792
$<.map{|s|a,b,c,d,e,f,g,h=s.split.map &:to_i;next if !b;puts [a*e-b*f-c*g-d*h,a*f+b*e+c*h-d*g,a*g-b*h+c*e+d*f,a*h+b*g-c*f+d*e]*' '}


Measured memory_bytes: 6912
# frozen_string_literal: true

n = gets.to_i
s = gets.chomp.chars
r = s.count { |c| c == 'R' }
g = s.count { |c| c == 'G' }
b = s.count { |c| c == 'B' }
cnt = 0

0.upto(n - 1) do |i|
  (i + 1).upto(n - 1) do |j|
    k = 2 * j - i
    cnt += 1 if k <= (n - 1) && s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
  end
end

puts r * g * b - cnt

Measured memory_bytes: 14436
def main(n500, n100, n50, price):
    count = 0
    for i in range(n500 + 1):
        if i * 500 <= price:
            for j in range(n100 + 1):
                if i * 500 + j * 100 <= price:
                    for k in range(n50 + 1):
                        p = i * 500 + j * 100 + k * 50
                        if p == price:
                            count += 1
    print(count)


if __name__ == "__main__":
    n500 = int(input())
    n100 = int(input())
    n50 = int(input())
    price = int(input())
    main(n500, n100, n50, price)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int t, n;
    int dx[]={1, 1, 0, -1, -1, 0};
    int dy[]={0, 1, 1, 0, -1, -1};
    while(cin>>t>>n, t){
        bool field[202][202];
        for(int i=0; i<=200; i++){
            for(int j=0; j<=200; j++){
                field[i][j]=true;
            }
        }
        while(n--){
            int x, y;
            cin >> x >> y;
            field[x+100][y+100]=false;
        }
        int sx, sy;
        cin >> sx >> sy;
        queue<pair<pair<int, int>,int>> q;
        bool visited[202][202];
        for(int i=0; i<=200; i++){
            for(int j=0; j<=200; j++){
                visited[i][j]=false;
            }
        }
        visited[sx+100][sy+100]=true;
        q.push(make_pair(make_pair(sx+100, sy+100),0));
        int count=0;
        while(!q.empty()){
            int nx=q.front().first.first, ny=q.front().first.second, now=q.front().second;
            if(now>t) break;
            count++;
            for(int i=0; i<6; i++){
                if(field[nx+dx[i]][ny+dy[i]]&&!visited[nx+dx[i]][ny+dy[i]]){
                    visited[nx+dx[i]][ny+dy[i]]=true;
                    q.push(make_pair(make_pair(nx+dx[i], ny+dy[i]),now+1));
                }
            }
            q.pop();
        }
        cout << count << "\n";
         
    }
     
}


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

string s;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>s;
    if(s.size()&1){
        cout<<"No"<<endl;
        return 0;
    }
    bool f=true;
    for(int i=0;i<s.size();i+=2){
        if(s[i]!='h'||s[i+1]!='i')f=false;
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

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

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

let main() =
    let [| n; r |] = reada int

    let ans =
        if n < 10 then r + (100 * (10 - n)) else r
    puts ans
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

vector< int64_t > divisor(int64_t n) {
    vector< int64_t > ret;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
        ret.push_back(i);
        if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(10);
    ll N;
    cin >> N;
    vector< int64_t > N1div = divisor(N-1);
    // rep(i,div.size()) {
    //     cout << div.at(i) << endl;
    // }
    ll N1divSize = N1div.size()-1;
    
    vector< int64_t > Ndiv = divisor(N);
    ll NdivAnsSize = 0;
    for (ll i = 1; i < Ndiv.size(); i++) {
        ll num = N;
        while(num>0) {
            if(num%Ndiv.at(i)==0) {
                num /= Ndiv.at(i);
            } else if (num%Ndiv.at(i)==1) {
                NdivAnsSize++;
                break;
            } else {
                break;
            }
        }
    }
    cout << N1divSize + NdivAnsSize << endl;
    // cout << N1divSize << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007
int cost[110000];


int main() {

	int N;
	cin>>N;
	vector<vector<int>> F(N+1);
  map<pair<int,int>,int> K;
	fx(N-1){
		int a,b,w;
		cin>>a>>b>>w;
		K[make_pair(a,b)]=w;
       K[make_pair(b,a)]=w;
		F.at(a).push_back(b);
		F.at(b).push_back(a);
	}

	bool Flag[N+10];
	fx(N+5){
		Flag[x]=false;
		cost[x]=INT_MAX/2;

	}
cost[1]=0;
	queue<int> H;
	H.push(1);
while(H.size()>0){ 
	
	int i=H.front();
	H.pop();
	if(Flag[i]){continue;}
   Flag[i] = true;                       
   for(int j=0;j<F.at(i).size();j++){  
     int k=K[make_pair(i,F.at(i).at(j))];
      cost[F.at(i).at(j)]=cost[i]+ k;
   		H.push(F.at(i).at(j));
   }
	
}

int ans[N+10];
ans[1]=0;
fyg(N+1,2){

	if(cost[y]%2==0){
		ans[y]=0;
	}else{
		ans[y]=1;
	}
}

fx(N){
	ce(ans[x+1])
}
}


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

using namespace std;

typedef long long ll;

#ifdef RED
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = (int)1e6 + 5;
const ll inf = (ll)1e18;

int n, W;
ll w[N], v[N];
ll dp[N];

int main() {
#ifdef RED
  freopen("a.in", "r", stdin);
#endif
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> W;
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> w[i] >> v[i];
    sum += v[i];
  }
  for (int i = 0; i <= sum; ++i) {
    dp[i] = inf;
  }
  dp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    vector <ll> mn(sum + 10);
    for (int j = v[i]; j <= sum; ++j) {
      mn[j] = min(dp[j], dp[j - v[i]] + w[i]);
    }
    for (int j = v[i]; j <= sum; ++j) {
      dp[j] = mn[j];
    }
  }
  for (int i = sum; i >= 0; i--) {
    if (dp[i] <= W) {
      cout << i;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 5888
import heapq
import itertools

def dijkstra(s):
    cost = [10**20] * (N+1)
    visited = [False] * (N+1)
    visited[s], cost[s] = True, 0
    q = []

    for r in route[s]:
        heapq.heappush(q, r)

    while q:
        c, r = heapq.heappop(q)

        if not visited[r]:
            visited[r] = True
            cost[r] = min(cost[r], c)

            for c_, n in route[r]:
                if not visited[n]:
                    heapq.heappush(q, (c+c_, n))

    return cost

N, M, R = map(int, input().split())
r_ = list(map(int, input().split()))
ans = 10**10
route = [[] for i in range(N+1)]

for i in range(M):
    A, B, C = map(int, input().split())
    route[A].append((C, B))
    route[B].append((C, A))

cost = {r:dijkstra(r) for r in r_}
for r in itertools.permutations(r_):
    total = 0

    for i in range(R-1):
        total += cost[r[i]][r[i+1]]
    ans = min(ans, total)
print(ans)

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

int main()
{
	int ninzu;
	int huda[3][200];
	int goukei[200];
	int kazoe[101];
	int i,j,k;

	cin>>ninzu;

	for(i=0;i<ninzu;i++){
		for(j=0;j<3;j++){
			cin>>huda[j][i];
		}
	}
	for(i=0;i<101;i++){
		kazoe[i]=0;
	}
	for(i=0;i<3;i++){
		for(j=0;j<101;j++){
			kazoe[j]=0;
		}
		for(j=0;j<ninzu;j++){
			kazoe[huda[i][j]]++;
		}
		for(j=0;j<101;j++){
			if(kazoe[j]>1){
				for(k=0;k<ninzu;k++){
					if(huda[i][k]==j){
						huda[i][k]=0;
					}
				}
			}
		}

	}
	for(i=0;i<ninzu;i++){
		goukei[i]=(huda[0][i]+huda[1][i]+huda[2][i]);
	}
	for(i=0;i<ninzu;i++){
		cout<<goukei[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
import sys

t, x, y = 0, 0, 0
for _ in range(input()):
    [t2, x2, y2] = map(int, raw_input().split())
    d1 = abs(x2 - x) + abs(y2 - y)
    d2 = t2 - t
    if d1 > d2:
        print 'No'
        sys.exit(0)
    if d1 == d2 or (d2 - d1) % 2 == 0:
        t = t2
        x = x2
        y = y2
    else:
        print 'No'
        sys.exit(0)
        
print 'Yes'


Measured memory_bytes: 5764
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
vector<LL> make_divisors(LL n){vector<LL> divisors;for(int i = 1; i <= sqrt(n); i++) {if(n%i == 0){divisors.push_back(i);if(i != n/i){divisors.push_back(n / i);}}}return divisors;}
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

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

    vector<int> d(N);
    rep(i, N) cin >> d[i];

    int ans = 0;
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

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

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int n; cin >> n;
	vector<int> v(n), w(n);
	for(int i=0; i<n; i++) cin >> v[i] >> w[i];
	int q; cin >> q;
	vector<int> u(q), l(q);
	for(int i=0; i<q; i++) cin >> u[i] >> l[i];

	vector<vector<pair<int, int>>> xs;

	const int H = 12;
	xs.push_back(vector<pair<int, int>>{{0, 0}, {w[0], v[0]}});
	for(int i=1; i<min(n, 1<<H); i++){
		vector<pair<int, int>> x(xs[(i-1)/2]);
		int m = x.size();
		for(int j=0; j<m; j++){
			x.push_back({x[j].first+w[i], x[j].second+v[i]});
		}
		sort(x.begin(), x.end());
		for(int j=1; j<x.size(); j++){
			x[j].second = max(x[j].second, x[j-1].second);
		}

		xs.push_back(x);
	}

	for(int i=0; i<q; i++){
		u[i]--;
		if(u[i]<(1<<H)){
			int ans = 0;
			int k = lower_bound(xs[u[i]].begin(), xs[u[i]].end(), pair<int, int>{l[i]+1, 0})-xs[u[i]].begin();
			if(k>0) ans = xs[u[i]][k-1].second;
			cout << ans << endl;
			continue;
		}

		vector<pair<int, int>> y(1, {0, 0});
		int t = u[i];
		while(t>=(1<<H)){
			int m = y.size();
			for(int j=0; j<m; j++){
				y.push_back({y[j].first+w[t], y[j].second+v[t]});
			}
			t = (t-1)/2;
		}

		int ans = 0;
		for(auto p: y){
			int k = lower_bound(xs[t].begin(), xs[t].end(), pair<int, int>{l[i]-p.first+1, 0}) - xs[t].begin();
			if(k==0) continue;
			ans = max(ans, p.second+xs[t][k-1].second);
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 93792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (100010)
int n,now=1,ans;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=5;i++){		
		if (i&1) ans+=min(n,now*10-1)-(now-1);
		now*=10;
		if (n<now) break;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   int k;
   cin >> n >> k;
   vector<char> cs(k);
   rep(i,k){
      cin >> cs[i];
   }
   bool f = true;
   while(f){
      bool can = true;
      rep(i,k){
         string tmp;
         tmp = to_string(n);
         for (int i = 0;i < tmp.size();i++){
            bool doit = true;
            for (int j = 0; j < k;j++){
               if (tmp[i] == cs[j]){
                  can = false;
                  doit = false;
                  break;
               }
            }
            if (!doit) break;
         }
      }
      if (can){
         cout << n << endl;
         return 0;
      }
      else n++;
   }

   
   return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N,M,H;
main()
{
	cin>>N;
	int cnt=0;
	for(int i=0;i<N;i++)
	{
		cin>>H;
		cnt+=M<=H;
		if(M<H)M=H;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>ll(b);i--)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
#define INF 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 
#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 
#define Umap unordered_map
#define Uset unordered_set


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

    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    vector<ll> B(M);
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];

    vector<ll> accum_A(N+1);
    accum_A.at(0) = 0;
    vector<ll> accum_B(M+1);
    accum_B.at(0) = 0;
    FOR(i, 1, N+1) accum_A.at(i) = accum_A.at(i-1) + A.at(i-1);
    FOR(i, 1, M+1) accum_B.at(i) = accum_B.at(i-1) + B.at(i-1);

    ll max_sassu = 0;
    ll i_m = M;
    FOR(i_n, 0, N+1) {
        if (accum_A[i_n] > K) {
            break;
        }

        while (accum_B[i_m] > K -accum_A[i_n]) i_m -= 1;

        max_sassu = max(i_n + i_m, max_sassu);
    }

    cout << max_sassu << endl;

    return 0;
}

Measured memory_bytes: 9512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

ll dp[90001];
void solve() {
	int n; cin >> n;
	vector<int> a(n); rep(i, n)cin >> a[i];
	ll ans = 1;
	rep(i, n) {
		ans = ans * 3 % mod;
	}
	int sum = 0;
	rep(i, n)sum += a[i];
	int inf = (1 + sum) / 2;
	dp[0] = 1;
	rep(i, n) {
		per(j, 90001) {
			if (j + a[i] <= 90000) {
				(dp[j + a[i]] += dp[j]) %= mod;
				dp[j] = dp[j] * 2 % mod;
			}
		}
	}
	ll u = 0;
	Rep(i, inf, 90001) {
		u = (u + dp[i]) % mod;
	}
	//cout << ans << " " << u << endl;
	u = 3 * u%mod;

	//2つがsum/2に一致
	if (sum % 2 == 0) {
		fill(dp, dp + 90001, 0); dp[0] = 1;
		rep(i, n) {
			per(j, 90001) {
				if (j + a[i] <= 90000) {
					(dp[j + a[i]] += dp[j]) %= mod;
				}
			}
		}
		ll z = dp[sum / 2];
		z = 3 * z%mod;
		ans = (ans + z) % mod;
	}

	ans = (ans - u + mod) % mod;
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

vector<lint> A;
vector<set<int>> e;

constexpr lint INF = 1e14;
vector<vector<lint>> dfs(int now, int prv)
{
    vector<vector<lint>> ret(1, vector<lint>(2));
    ret[0][0] = (A[now] > 0 ? A[now] : INF);
    ret[0][1] = (A[now] < 0 ? A[now] : INF);
    for (auto nxt : e[now]) if (nxt != prv)
    {
        auto tmp = dfs(nxt, now);
        vector<vector<lint>> retnew(ret.size() + tmp.size(), vector<lint>(2, INF));
        REP(i, ret.size()) REP(j, tmp.size())
        {
            REP(d, 2) REP(e, 2) mmin(retnew[i + j][d | e], ret[i][d] + tmp[j][e]);
            REP(d, 2)
            {
                if (tmp[j][0] < INF) mmin(retnew[i + j + 1][d], ret[i][d]);
                if (tmp[j][1] < 0) mmin(retnew[i + j + 1][d], ret[i][d]);
            }
        }
        ret = retnew;
    }
    return ret;
}

int main()
{
    int N;
    cin >> N;
    A.resize(N);
    cin >> A;
    e.resize(N);
    REP(_, N - 1)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        e[u].insert(v);
        e[v].insert(u);
    }
    auto ret = dfs(0, -1);
    REP(i, N)
    {
        if (ret[i][0] < INF or ret[i][1] < 0)
        {
            cout << i << endl;
            return 0;
        }
    }
}


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

int solve(int p, int q, int a, int n, int t) {
    int res = 0;
    if(p == 0) {
        return 1;
    }
    if(n == 0 || p < 0) {
        return 0;
    }
    for(int i=t; i<=a; ++i) {
        res += solve(p*i-q, q*i, a / i, n-1, i);
    }
    return res;
}

int main() {
    int p, q, a, n;
    while(cin >> p >> q >> a >> n, p) {
        cout << solve(p, q, a, n, 1) << endl;
    }
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,a,n) for(int i=a;i<n;i++)
 main(){
  int c1=0,c2=0,c3=0;
  string s,t,p1,p2;
  cin>>s>>t;
  r(i,s.size())
    if(i%2)p1+=s[i];
    else p2+=s[i];
  r(j,p1.size()){
    int c=0;
   R(i,c1,t.size())
    if(t[i]==p1[j]){
      c1=i+1,c++,c3++;
      break;
    }
  }
  if(c3==p1.size())goto M;
  r(j,p2.size()){
    int c=0;
   R(i,c2,t.size())
    if(t[i]==p2[j]){
      c2=i+1,c++;
      break;
    }
    if(!c)goto L;
  }
  M:cout<<"Yes"<<endl;
  if(0)L:cout<<"No"<<endl;
}

Measured memory_bytes: 3192
#include<iostream>
#include<string>
int i,j;main(){std::string s[8],t;for(;i<8;)getline(std::cin,s[i++]);for(t="90\n";i-->0;t+="\n")for(j=8;j-->0;)t+=s[j][7-i];for(t+="180\n";++i<8;t+="\n")for(j=8;j-->0;)t+=s[7-i][j];for(t+="270\n";i-->0;t+="\n")for(j=0;j<8;)t+=s[j++][i];std::cout<<t;return 0;}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

//char arr[57][57];
int main(){
	Lancer();
	ll n, m, ans = 0;
	cin >> n;
	vector<string>blue(n);
	for (int i = 0; i < n; i++)
		cin >> blue[i];
	cin >> m;

	vector<string>red(m);
	for (int i = 0; i < m; i++)
		cin >> red[i];

	for (int i = 0; i < n; i++){
		bool ch = true;
		ll t = 0;
		for (int j = 0; j < m; j++){
			if (blue[i] == red[j])t--;
			
		}
		for (int j = 0; j < n; j++){
			if (blue[i] == blue[j])
				t++;
		}
		ans = max(t, ans);
	}
	cout << ans;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3692
using System;
using System.Linq;
using System.Numerics;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            long[] As = ToLongArray(input);
            long MAX = (long)Math.Pow(10,18);
            if(As.Contains(0))
            {
                Console.WriteLine(0);
                return;
            }
            BigInteger total = 1;
            for(long i = 0; i < n ; i++)
            {
                if(MAX < total * As[i])
                {
                    Console.WriteLine("-1");
                    return;
                }else{
                    total *= As[i];
                }
            }
            
            Console.WriteLine(total);
        }
    }
    //2回位使ったら追加する
    class MyLibrary
    {
        public static long[] ToLongArray(string[] stringArray)
        {
            long length = stringArray.Length;
            long[] longArray = new long[length];
            for (long i = 0; i < length; i++)
            {
                longArray[i] = long.Parse(stringArray[i]);
            }
            return longArray;
        }
    }
}


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

using namespace std;

int main(){
 char letter;
 cin >> letter;
 char alphabet[5] = {'a', 'e', 'i', 'o', 'u'};

    if (find(begin(alphabet), end(alphabet), letter) != end(alphabet))
        cout << "vowel";
    else
        cout << "consonant";

  //system("pause");
  return 0;
}

Measured memory_bytes: 760
cids = {}
counts = (0..1000).map{0}
months = (0..1000).map{0}

while true
  str = gets.chomp
  break if str == ""

  id, d = str.split(" ").map{|s| s.to_i}

  cids[id] = true
  counts[id] += 1
  months[id] |= 1
end

while (line = gets)
  id ,d = line.chomp.split(" ").map{|s| s.to_i}

  cids[id] = true
  counts[id] += 1
  months[id] |= 2
end

cids.keys.sort.select{|id| months[id] == 3}.each do |id|
  puts [id, counts[id]].join(" ")
end

Measured memory_bytes: 6136
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector<vector<ll>> g;

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n,m;
  cin >> n >> m;
  g.resize(n);
  rep(i,m) {
    ll a,b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> dp(n, -1); // source
  // Do bfs
  queue<int> q;
  q.push(0);
  dp[0] = INF; // set sentinel
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : g[v]) {
      if (dp[u] == -1) {
        dp[u] = v; // source if v.
        q.push(u);
      }
    }
  }

  // Here, all travere is completed.
  bool ok = true;
  rep(i,n) {
    if (dp[i] == -1) { // unvisited
      ok = false;
      break;
    }
  }
  if (!ok) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) {
    cout << dp[i]+1 << endl; // 1-indexed
  }
}


Measured memory_bytes: 12340
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
    string a,b,c; cin >> a >> b >> c;

    char d = 'A' - 'a';
    cout << char(a[0] + d) << char(b[0] + d) << char(c[0] + d) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void){
    int A,B;
    cin>>A>>B;

    if(A<=5){
        cout<<"0"<<endl;
    }else if(A<=12){
        cout<<B/2<<endl;
    }else{
        cout<<B<<endl;
    }


    return 0;
}

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

int main(){
	string input;
	cin >> input;
	for(int i=0; i < input.size(); i++){
		input[i] -= 3;
		if(input[i] < 'A') input[i] += 26;
	}
	cout << input << endl;
}

Measured memory_bytes: 1180
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n:usize,
        ass: [usize;n],
    }
    let mut alice = 0;
    let mut bob = 0;
    let mut asss = ass;
    asss.sort_by(|a,b|b.cmp(a));
    for (i,a) in asss.iter().enumerate(){
        if i % 2 == 0 {
            alice += *a;
        }else{
            bob += *a;
        }
    }
    println!("{}",alice - bob);
}    


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


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c >= 22)cout << "bust\n";
    else cout << "win\n";
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll pre[1000005],prim[1000005]={0};
vector<ll> mp(1000005,0);
void sieve(ll n)
{
	ll i,j;
	for(i=2;i<=n;i++)
	{
		if(prim[i]==0)
		{
			pre[i]=i;
			for(j=i*i;j<=n;j+=i)
			{	
				prim[j]++;
				if(pre[j]==0)
				pre[j]=i;
			}
		}
		
	}
}

void factor(ll x)
{
	ll z=x;
	while(x!=1)
	{
		mp[x]++;
		x=x/pre[x];
	}
}
int main()
{
	ll i,j,n;
	cin>>n;
	ll a[n+5];
	sieve(1000000);
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll g=a[0];
	for(i=1;i<n;i++)
	{
		g=__gcd(g,a[i]);
	}
	if(g!=1)
	{
		cout<<"not coprime\n";
		return 0;
	}
	for(i=0;i<n;i++)
	{
		factor(a[i]);
	}
	for(i=1;i<=1000000;i++)
	{
		if(mp[i]>1)
		{
			cout<<"setwise coprime";
			return 0;
		}
	}
	cout<<"pairwise coprime";
}

Measured memory_bytes: 34420
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int MaxN = 1e5;
int n, a[MaxN + 5];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int flag = 0; a[0] = a[1]; int tot = 1;
	for(int i = 1; i <= n; i++) {
		if(!flag) {
			if(a[i] == a[i - 1]) flag = 0;
			else if(a[i] > a[i - 1]) flag = 1;
				else flag = -1;
		}
		else if(flag == 1){
			if(a[i] < a[i - 1]) flag = 0, tot++;
		}
		else {
			if(a[i] > a[i - 1]) flag = 0, tot++;
		}
	}
	printf("%d\n", tot);
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=2e5+3;


const unsigned long long B=1e12+7;


int main(){
    int m1,m2,d1,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1<m2)cout<<1<<endl;
    else cout<<0<<endl;
    
    return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
dp=[10**5]*n
for i in range(n):
  if i==0:
    dp[i]=0
  elif i==1:
    dp[i]=abs(h[1]-h[0])
  else:
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 85108
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

//DPの中では簡単な問題_typical stair
int main(){
    ll N,M;
    cin >> N >> M;
    vector<bool> koware(N+1);
    koware.assign(N+1,true);

    for(ll i = 0;i < M;i++){
        ll a;
        cin >> a;
        koware.at(a) = false;
    }

    //DPで初期化
    vector<ll> dp(N+1,0);

    //初期条件
    dp[0] = 1;
    if(koware[1])
        dp[1] = 1;
    
    for(ll i = 2;i <= N;i++){
        if(koware.at(i-2))
            dp[i] += dp[i-2];
        if(koware.at(i-1))
            dp[i] += dp[i-1];
        dp[i] %= MOD;
    }

    cout << dp[N] << endl; 

    return 0;
}

Measured memory_bytes: 3980
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    int N; cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    bool odd = false;
    int ans = 0;
    while(!odd){
        REP(i,N){
            if (A[i] % 2 == 0){
                 A[i] = A[i] / 2;   
            }else{
                odd = true;
                ans -= 1;
                break;
            }
        }
        ans += 1;

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

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

// main
int main(){
    string S;
    cin >> S;

    reverse(S.begin(), S.end());

    string div_str[4] = {"dream", "dreamer", "erase", "eraser"};
    for(int i=0; i<4; ++i){
        reverse(div_str[i].begin(), div_str[i].end());
    }

    bool is_can_div_all = true;
    for(int i=0; i < (int)S.size();){
        bool is_can_div = false;
        for(int j = 0; j < 4; ++j){
            string d = div_str[j];
            if(S.substr(i, d.size()) == d){
                is_can_div = true;
                i += d.size();
                break;
            }
        }
        if(!is_can_div){
            is_can_div_all = false;
            break;
        }
    }

    if(is_can_div_all) cout << "YES" << "\n";
    else cout << "NO" << "\n";

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    string s;cin>>s;
    int N=s.size();
    int x,y;cin>>x>>y;

    vec u_d,l_r;
    int t=0,i=0,f=0;
    while(i<N){
        if(s[i]=='F')f++;
        if(s[i]=='T' || i==N-1){
            if(t%2==0)l_r.push_back(f);
            else      u_d.push_back(f);
            f=0;t++;
        }
        i++;  
    }

    int LR=l_r.size(),UD=u_d.size();
    set<int> S_UD[10000],S_LR[10000];
    S_LR[1].insert(l_r[0]);
    S_UD[0].insert(0);
    int z;
    for(int i=1;i<LR;i++){
        z=l_r[i];
        for(auto itr=S_LR[i].begin();itr!=S_LR[i].end();itr++){
            if(S_LR[i+1].find(*itr+z)==S_LR[i+1].end())S_LR[i+1].insert(*itr+z);
            if(S_LR[i+1].find(*itr-z)==S_LR[i+1].end())S_LR[i+1].insert(*itr-z);
        }        
    }
    for(int i=0;i<UD;i++){
        z=u_d[i];
        for(auto itr=S_UD[i].begin();itr!=S_UD[i].end();itr++){
            if(S_UD[i+1].find(*itr+z)==S_UD[i+1].end())S_UD[i+1].insert(*itr+z);
            if(S_UD[i+1].find(*itr-z)==S_UD[i+1].end())S_UD[i+1].insert(*itr-z);
        }
    }
    if(S_LR[LR].find(x)!=S_LR[LR].end() && S_UD[UD].find(y)!=S_UD[UD].end())
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 232960
from collections import deque
N, M = map(int, input().split())
graph = [] 
for i in range(N + M - 1):
    a, b = map(int, input().split())
    graph += [[a,b]]

path = [[] for i in range(N)]  
parent = [[] for i in range(N)]
ans = [-1 for i in range(N)]
for p in graph:
    parent[p[1]-1] += [p[0]-1]
    path[p[0]-1] += [p[1]-1]

root = -1
for i in range(N):
    if parent[i] == []:
        root = i
        parent[i] = [-1]
visited = [0 for i in range(N)]
visited[root] = 1

que = deque()
for v in path[root]:
    ans[v] = root
    if len(parent[v]) > 1:
        parent[v].remove(root) 
    else: que.append([root, v])
while que:
    u, V = que.popleft()
    for v in path[V]:
        if len(parent[v]) > 1:
            parent[v].remove(V)
        else:
            que.append([V, v])
for i in range(N):
    print(parent[i][0]+1)

Measured memory_bytes: 57824
fun main(args: Array<String>) {
    val (a, b, c) = readInputLine().split(" ").map { it.toLong() }

    if (c <= a + b) {
        println("No")
        return
    }

    if ((c - a - b) * (c - a - b) > 4 * a * b) {
        println("Yes")
    } else {
        println("No")
    }

}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37892
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    a = map(int, input().split())
    ans = 0
    for i in a:
        while i % 2 == 0:
            i //= 2
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#include<stdio.h>
#include<algorithm>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <iostream>
#include <time.h>
#include <functional>
using namespace std;

int n = 0;
int A[100001] = { 0 };
int L[100001] = { 0 };

int main(void) {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	L[0] = A[0];
	int length = 1;
	for (int i = 1; i < n; ++i) {
		if (L[length - 1] < A[i]) {
			L[length++] = A[i];
		}
		else {
			int right = length - 1, left = 0;
			int cent = 0;
			while (left <= right) {
				cent = (left + right) / 2;
				if (L[cent] > A[i]) {
					if (cent == 0 || L[cent - 1] < A[i]) {
						L[cent] = A[i];
					}
				}
				if (L[cent] < A[i]) { left = cent + 1; }
				else { right = cent - 1; }
			}
		}
	}
	printf("%d\n", length);
}

Measured memory_bytes: 3868
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		long k = sc.nextInt();
		ArrayList<Unit> list = new ArrayList<>();
		char prev = arr[0];
		int len = 1;
		for (int i = 1; i < arr.length; i++) {
		    if (prev == arr[i]) {
		        len++;
		    } else {
		        list.add(new Unit(prev, len));
		        prev = arr[i];
		        len = 1;
		    }
		}
		list.add(new Unit(prev, len));
		if (list.size() == 1) {
		    System.out.println(list.get(0).length * k / 2);
		    return;
		}
		Unit first = list.get(0);
		Unit last = list.get(list.size() - 1);
		long ans = 0;
		if (first.c == last.c) {
		    ans += (first.length + last.length) / 2 * (k - 1);
		    ans += first.length / 2;
		    ans += last.length / 2;
		    list.remove(list.size() - 1);
		    list.remove(0);
		}
		for (Unit u : list) {
		    ans += u.length / 2 * k;
		}
		System.out.println(ans);
	}
	
	static class Unit {
	    char c;
	    int length;
	    public Unit(char c, int length) {
	        this.c = c;
	        this.length = length;
	    }
	}
}


Measured memory_bytes: 22228
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct Node{
    int val;
    Node* lhs, *rhs;
    Node(int val):val(val),lhs(nullptr),rhs(nullptr){}
};

Node* update(Node* t,int l, int r,int k,int x){
    if(k<l||r<=k)return t;
    if(l+1==r){
        Node* ret = new Node(x);
        return ret;
    }
    int mid=(l+r)/2;
    Node* ret = new Node(inf);
    ret->lhs = update(t->lhs,l,mid,k,x);
    ret->rhs = update(t->rhs,mid,r,k,x);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}

int query(Node* t,int a,int b, int l, int r){
    if(b<=l||r<=a)return inf;
    if(a<=l&&r<=b)return t->val;
    int vl = query(t->lhs, a,b,l,(l+r)/2);
    int vr = query(t->rhs, a,b,(l+r)/2, r);
    return min(vl,vr);
}

Node* build(vector<int>& v, int l, int r){
    Node* ret = new Node(inf);
    if(l+1==r){
        ret->val=v[l];
        return ret;
    }
    ret->lhs = build(v,l,(l+r)/2);
    ret->rhs = build(v,(l+r)/2,r);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}
int main(){
    int n;
    cin>>n;
    int m=1;
    while(m<n)m*=2;
    vector<int> a(m,inf), b(m,inf);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    Node* A = build(a,0,m);
    Node* B = build(b,0,m);
    int q;
    cin>>q;
    while(q--){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        --y;
        if(x==1){
            A = update(A, 0, m, y, z);
        }
        if(x==2){
            B = update(B, 0, m, y, z);
        }
        if(x==5){
            A = B;
        }
        if(x==6){
            B = A;
        }
        if(x==3){
            printf("%d\n",query(A,y,z,0,m));
        }
        if(x==4){
            printf("%d\n",query(B,y,z,0,m));
        }
    }
    return 0;
}


Measured memory_bytes: 91380
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;

vector<string> maze;
int R, C;
const int INF = 10000000;
int sx, sy, gx, gy;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
/* 各点までの距離を格納 */
int d[510][510];

int bfs(){
    queue<P> que;

    rep(i,R){
        rep(j, C){
            d[i][j] = INF;
        }
    }

    que.push(P(sx, sy));
    d[sx][sy] = 0;

    while(que.size()){
        P p = que.front();
        que.pop();

        /* if(p.first == gx && p.second == gy) break; */

        for(int dir = 0; dir < 4; dir++){
            int nx = p.first + dx[dir];
            int ny = p.second + dy[dir];
            /*  */
            if(0 <= nx && 0 <= ny && nx < R && ny < C && maze[nx][ny] != '#' && d[nx][ny] == INF){
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gy][gx];
}

/* void clear_seen(){
    rep(i, 15){
        rep(j, 15){
            seen[i][j] = false;
        }
    }
} */

signed main() {
    bool isOk = false;
    cin >> R >> C;
    sx = 0, sy = 0, gx = C-1, gy = R-1;

    maze.resize(R);
    rep(i, R){
        cin >> maze[i];
    }

    int brack = 0;
    rep(i, R){
        rep(j, C){
            if(maze[i][j] == '#') brack++;
        }
    }

    int route = bfs() + 1;
    if(route == INF + 1){
        cout << -1 << endl;
        return 0;
    }

    cout << R * C - route - brack << endl;
    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, a, b);
  out(b % a == 0 ? a + b : b - a);
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.TreeSet;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) throws Exception {
         
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        br.readLine();
        String[] s = br.readLine().split(" ");
        br.readLine();
        String[] t = br.readLine().split(" ");
         
        Set<String> set = new TreeSet<String>(Arrays.asList(s));
        set.retainAll(Arrays.asList(t));
        System.out.println(set.size());
    }
}


Measured memory_bytes: 30668