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

class Main
{

	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str;
		double[] ans=new double[2];
		double det=0;
		while((str=br.readLine())!=null)
		{
			String[] aa=str.split(" ");
			double[] a=new double[aa.length];
			for(int i=0;i<aa.length;i++)
			{
				a[i]=Double.parseDouble(aa[i]);
			}
			det=a[0]*a[4]-a[1]*a[3];
			ans[0]=(a[4]*a[2]-a[1]*a[5])/det;
			ans[1]=(-a[3]*a[2]+a[0]*a[5])/det;
			for(int i=0;i<2;i++)
			{
				if(ans[i]==0){ans[i]=0;}

			}

			System.out.printf("%.3f %.3f\n",ans[0],ans[1]);


		}
	}
}

Measured memory_bytes: 24588
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int arr[200200];
int main()
{
    int n,i,j,k,x,y,ans,temp,curr,m;
    int tc;
    cin >> k >> n;
    for(i=1;i<=n;i++)
    {
        cin >> arr[i];
    }
    int chaeng = 1e9;
    for(i=1;i<n;i++)
    {
        chaeng = min(chaeng, k - (arr[i+1] - arr[i]));
    }
    int a = arr[1];
    int b = k - arr[n];
    chaeng = min(chaeng, k - a - b);
    cout << chaeng << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int start = Math.max(a,c);
		int end = Math.min(b, d);
		
		int ans = end - start;
		
		if(ans <= 0){
			System.out.println(0);
		}
		else{
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ans(n+1);
    int r=0,l=0,now;
    rep(i,n-1){
        if(s[i]=='R'&&s[i+1]=='R'){
            r++;
        }
        else if(s[i]=='R'&&s[i+1]=='L'){
            now = i;
            ans[now]+=r/2+1;
            ans[now+1]+=(r+1)/2+1;
            r=0;
        }
        else if(s[i]=='L'&&s[i+1]=='L'){
            l++;
        }
        else if(s[i]=='L'&&s[i+1]=='R'){
            ans[now]+=(l+1)/2;
            ans[now+1]+=l/2;
            l=0;
        }
    }
    ans[now]+=(l+1)/2;
    ans[now+1]+=l/2;
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back
typedef pair<LL, LL> P;
typedef pair<LL, P> PP;

LL a[2020200];
LL b[2020200];
LL n;

bool calc(LL m) {
	for (int i = 0; i < n; i++) {
		LL tmp = (i == 0 ? 0 : b[i - 1]);
		int pos1 = lower_bound(b + i, b + i + n, tmp + m) - b;
		int pos2 = lower_bound(b + i, b + i + n, b[pos1] + m) - b;
		if (b[n + i - 1] - b[pos2] >= m)return true;
	}
	return false;
}


int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = n; i < n * 2; i++) {
		a[i] = a[i - n];
	}
	b[0] = a[0];
	for (int i = 1; i < n * 2; i++) {
		b[i] = a[i] + b[i - 1];
	}

	LL left = 1, right = b[n - 1];
	while (right - left > 1) {
		LL mid = (right + left) / 2;
		if (calc(mid)) {
			left = mid;
		}
		else {
			right = mid;
		}
	}
	cout << left << endl;
	//system("pause");
}

Measured memory_bytes: 6224
#include <bits/stdc++.h>
#define int long long 
 
using namespace std;
 
int32_t main() {
  int n, k; cin >> n >> k;
  
  set<int> s1, s2, s3;
  for (int i = 0; i < 3 * n; ++i) {
    if (i < n) s1.insert(k + i);
    else if (i < 2 * n) s2.insert(k + i);
    else s3.insert(k + i);
  }

  auto pop = [&](set<int>& x, int maxx) {
    auto it = x.upper_bound(maxx);
    if (it == x.begin()) return -1LL;
    int ret = *prev(it);
    x.erase(prev(it));
    return ret;
  };
 
  vector<tuple<int, int, int>> sol;
  bool par = false;
  for (int i = 0; i < n; ++i) {
    int a, b, c;

    c = pop(s3, 2e18);
    if (par) {
      b = pop(s2, 2e18);
      a = pop(s1, c - b);
    } else {
      a = pop(s1, 2e18);
      b = pop(s2, c - a);
    }
    if (a < 0 || b < 0) {
      cout << -1 << endl;
      return 0;
    }
    sol.emplace_back(a, b, c);
    par = !par;
  }
 
  for (auto itr : sol) {
    int a, b, c; tie(a, b, c) = itr;
    cout << a << " " << b << " " << c << '\n';
  }
    
  return 0;
}


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

int main () { 
int s , k ,z ; 
scanf ("%d%d", &k,&s) ; 
int c=0; 

 for (int x=0  ; (0<=x&&x<=k)  ; x++ ) { 
    for (int y=0 ; (0<=y&&y<=k) ; y++ ) 
    { 
      
	    z=s-(x+y); 
	    if(0<=z&&z<=k  )
        	if(x+z+y==s) 
             c++ ;  
		
	}

}
  
printf("%d",c);
return 0; 
}

Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:36777216")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <complex>
#include <ctime>
#include <stack>

//#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define FOR(i, x, y) for(int i = (x); i <= (y); ++i)
#define RFOR(i, y, x) for(int i = (x); i >= (y); --i)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a)) 
#define CLEAR(x) memset(x, 0, sizeof x);
#define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define mk make_pair
#define sqr(x) ((x)*(x))
#define X first
#define Y second
//typedef tree<int, null_type, less<int>, 
//  rb_tree_tag, tree_order_statistics_node_update> order_set;

//const long double PI = acos(-1.0);
//const double EPS = 1E-6;
//const int INF = 2 * (1e+9) + 1;
//const int MAXN = 3 * 100000001;
//const int MOD = (1e+9) + 7;


int a, b, c, k;
int main() {
    cin >> a >> b >> c >> k;
    int sum = 0;
    sum += min(a, k);
    k -= min(a, k);
    if (k) {
        k -= min(b, k);
    }
    if (k > 0) {
        sum -= min(c, k);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3192
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

main = do
  [x,y,z] <- getInts
  print $ minimum [z `mod` 2 * x * y, x `mod` 2 * z * y, y `mod` 2 * x * z]

-- util
getInts :: IO [Integer]
getInts = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine

substr :: Int -> Int -> B.ByteString -> B.ByteString
substr b l s = B.take l $ B.drop b s


Measured memory_bytes: 380
n=gets
h=gets.split.map(&:to_i)
h.reverse!
(h.size-1).times do |i|
  if h[i] >= h[i+1]
    next
  else
    h[i+1] -= 1
    if h[i] >= h[i+1]
      next
    else
      puts "No"
      exit
    end
  end
end

puts "Yes"

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <complex>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,a) FOR(i,0,a)
#define SQR(a) ((a)*(a))
#define X first
#define Y second
using namespace std;
typedef long long int ll;
typedef pair<int,int> pr;
typedef pair<pr,ll> ppr;
typedef vector<pr> vpr;
typedef pair<int,int> ci;
typedef pair<int,ci> pci;
typedef priority_queue<pci,vector<pci>,greater<pci> > pq;
const int INF=1<<30;
bool finished[502][502];
int level[502][502];
ci dc[4]={ci(1,0),ci(0,1),ci(-1,0),ci(0,-1)};
int main() {
	int R;
	while(cin >> R && R){
	vpr ables[2];
	REP(l,2){
		int W,H,sx,sy,mlevel=0,sum=0;
		cin >> W  >>H >>sx >> sy;
		FORE(i,1,H)
			FORE(j,1,W)
				scanf("%d",&level[i][j]);
		FORE(i,0,H+1)
			FORE(j,0,W+1)
				if(i&&j&&i<=H&&j<=W)
					finished[i][j]=false;
				else
					finished[i][j]=true;
		finished[sy][sx]=false;
		level[sy][sx]=INF;
		pq dungeon;
		dungeon.push(pci(1,ci(sx,sy)));
		while(!dungeon.empty()){
			ci point=dungeon.top().second;
			int nowlevel=dungeon.top().first;
			dungeon.pop();
			if(mlevel<nowlevel){
				ables[l].push_back(pr(sum,mlevel));
				mlevel=nowlevel;
			}
			sum++;
			REP(i,4){
				ci d=dc[i];
				if(!finished[point.Y+d.Y][point.X+d.X]){
					finished[point.Y+d.Y][point.X+d.X]=true;
					dungeon.push(pci(level[point.Y+d.Y][point.X+d.X],ci(point.X+d.X,point.Y+d.Y)));
				}
				
			}
		}
	}
	int e=ables[1].size()-1,minium=INF;
	REP(i,ables[0].size()){
		while(e && ables[0][i].first+ables[1][e-1].first>=R) e--;
		if(ables[0][i].first+ables[1][e].first>=R)
			minium=min(minium,ables[0][i].second+ables[1][e].second);
	}
	cout << minium << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 5152
class UnionFind():
    def __init__(self, n):
        self.parent = list(range(n))
        self.rank = [0] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


while True:
    try:
        n = int(input())
    except EOFError:
        break
    tree = UnionFind(7)
    nums = [0] * 7
    for dominoes in input().split():
        x, y = divmod(int(dominoes), 10)
        tree.unite(x, y)
        nums[x] += 1
        nums[y] += 1
    if all(tree.same(x, i) for i in range(1, 7) if nums[i]) and \
       sum(1 for x in nums if x % 2) <= 2:
        print('Yes')
    else:
        print('No')

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n-k){
        if(a[i]<a[i+k]) cout << "Yes" << "\n";
        else cout << "No" << "\n";
    }
    return 0;
}   

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int>p(N+1);
    for(int i=0;i<N;i++)cin>>p[i];
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    int sum=0;
    for (int i=0;i<N;i++){
        if(i==0){
            sum+=p[i]/2;
        continue;
        }
        sum+=p[i];
    }
    cout<<sum<<endl;
}

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

char s[100010];
char t[100010];

int ans[100010];
int main(){
	scanf("%s %s",s,t);
	int sm=(s[0]=='-'),tm=(t[0]=='-');
	int sn=strlen(s+sm),tn=strlen(t+tm);
	for(int i=0;i<sn;i++){
		if(sm)ans[i]-=s[sn+sm-1-i]-'0';
		else ans[i]+=s[sn-1-i]-'0';
	}
	for(int i=0;i<tn;i++){
		if(tm)ans[i]+=t[tn+tm-1-i]-'0';
		else ans[i]-=t[tn-1-i]-'0';
	}
	for(int i=0;i<100005;i++){
		while(ans[i]<0)ans[i]+=10,ans[i+1]--;
		while(ans[i]>9)ans[i]-=10,ans[i+1]++;
	}
	if(ans[100005]<0){
		printf("-");
		for(int i=0;i<100005;i++)ans[i]=9-ans[i];
		ans[0]++;
		int crr=0;
		while(ans[crr]==10)ans[crr]=0,ans[++crr]++;
	}
	int digit=0;
	for(int i=0;i<100005;i++)if(ans[i])digit=i;
	for(int i=digit;i>=0;i--)printf("%d",ans[i]);
	puts("");
}


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

int main() {
    int N;
    bool Y = false;
    cin >> N;
    for (int i = 0; i < N; i++){
        string S;
        cin >> S;
        if (S == "Y"){
            Y = true;
        }
    }
    if (Y)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)

const ll MAX_N = 1000;
const ll MAX_K = 3000;
ll D[MAX_N * MAX_N];
ll E[MAX_K * MAX_N];

int main(void){
    ll X, Y, Z, K;
    ll A[MAX_N], B[MAX_N], C[MAX_N];
    ll answer;

    cin >> X >> Y >> Z >> K;
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];

    //sort(rall(A));
    //sort(rall(B));
    //sort(rall(C));
    sort(A, A + X, greater<ll>());
    sort(B, B + Y, greater<ll>());
    sort(C, C + Z, greater<ll>());

    ll cnt = 0;

    rep(a, X){
        rep(b, Y){
            D[cnt] = A[a] + B[b];
            cnt ++;
        }
    }

    //sort(rall(D));
    sort(D, D + X * Y, greater<ll>());
    cnt = 0;

    rep(k, K){
        rep(c, Z){
            E[cnt] = D[k] + C[c];
            cnt ++;
        }
    }

    //sort(rall(E));
    sort(E, E + K * Z, greater<ll>());

    rep(i, K) cout << E[i] << endl;

    return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

const int maxN = 3010;

using namespace std;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define PINT pair < int, int >
#define BIT(x, i) ((x >> i) & 1)
#define NUM_SET_BIT __builtin_popcountll

int a, b, c, d, e, f, g[maxN][maxN], res1, res2;

double density(int i, int j) {
    return (100.0 * j) / (100.0 * i + j);
}

int main() {
    g[0][0] = 1;
    cin >> a >> b >> c >> d >> e >> f;
    FORU(i, 0, f / 100)
        FORU(j, 0, e * i) {
            if (i * 100 + j > f) break;
            if (i >= a)
                g[i][j] |= g[i - a][j];
            if (i >= b)
                g[i][j] |= g[i - b][j];
            if (j >= c)
                g[i][j] |= g[i][j - c];
            if (j >= d)
                g[i][j] |= g[i][j - d];
            if (g[i][j])
                if ((res1 == 0 && res2 == 0) || density(res1, res2) <= density(i, j))
                    res1 = i, res2 = j;
        }
    cout << res1 * 100 + res2 << " " << res2;
}


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

int n,m,ans=0;
vector<vector<int>> g(8);
vector<int> c(8),d;
void dfs(int k,int cnt){
  c.at(k)=1;
  d.push_back(k);
  if(cnt==n){
    ans++;
//    for(auto y:d) cout<<y+1<<' ';
//    cout<<endl;
  }
  else{
    for(auto z:g.at(k)) if(c.at(z)==0) dfs(z,cnt+1);
  }
  c.at(k)=0;
  d.erase(prev(d.end(),1));
}
int main(){
  int x,y,i;
  cin>>n>>m;
  for(i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    g.at(x).push_back(y);
    g.at(y).push_back(x);
  }
  dfs(0,1);
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define F first
#define S second
#define int long long

const int maxn = 310;
const ll inf = 1e18+10;
//const int mod = 998244353;
//const int mod = 1e9+7;

int n, m;
int a[maxn][maxn], ptr[maxn], cnt[maxn];
bool mark[maxn];

bool ok(int q)
{
   // cout<< q <<" ";
    set<pair<int,int>> se;
    for(int i = 1; i <= m; i++) cnt[i] = 0;
    for(int i = 1; i <= n; i++)
    {
        ptr[i] = 1;
        cnt[a[i][ptr[i]]]++;
    }
    for(int i = 1; i <= m; i++)
    {
        se.insert({cnt[i],i});
        mark[i] = 0;
    }

    while(se.size())
    {
        // cout<< se.size() <<" ";
        auto it = se.end(); it--;
        int X = (*it).S;
        //cout<< X <<" "<< cnt[X] <<" \n";
        if(cnt[X] <= q) return 1;

        se.erase(it);
        if(se.empty()) return 0;

        mark[X] = 1;
        for(int i = 1; i <= n; i++)
        {
            if(mark[a[i][ptr[i]]] == 0) continue;
            while(mark[a[i][ptr[i]]])
                ptr[i]++;
          //  if(X == 2)
          //      cout<< i <<" "<< ptr[i] <<"\n";
            int Y = a[i][ptr[i]];
            se.erase({cnt[Y],Y});
            cnt[Y]++;

          //  if(X == 2)
         //       cout<< Y <<" "<< cnt[Y] <<"\n";

            se.insert({cnt[Y],Y});
        }
    }
    return 0;
}

signed main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin>> a[i][j];

    int hi = n+1, lo = 0;
    while(hi-lo > 1)
    {
        int tm = (hi+lo) >> 1;
        if(ok(tm)) hi = tm;
        else lo = tm;
    }
    //cout<< ok(2) <<" ";
    cout<< hi;
}




Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, P> Pll;
int par[200002];
int rk[200002];
 
void init(int n){
	for(int i=0; i<n; i++){
		par[i]=i;
		rk[i]=0;
	}
}
 
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
 
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rk[x]<rk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rk[x]==rk[y]) rk[x]++;
	}
}
 
bool same(int x, int y){
	return find(x)==find(y);
}

int main()
{
	int n, m, k;
	cin>>n>>m>>k;
	init(n+k);
	int c[100000];
	int ct[100000]={};
	for(int i=0; i<n; i++){
		cin>>c[i];
		if(c[i]){
			unite(i, n+c[i]-1);
			ct[c[i]-1]++;
		}
	}
	int ct0=0;
	for(int i=0; i<k; i++){
		if(ct[i]>0) ct0+=(ct[i]-1);
	}
	Pll e[100000];
	for(int i=0; i<m; i++){
		int a, b; ll w;
		cin>>a>>b>>w;
		a--; b--;
		unite(a, b);
		e[i]=Pll(w, P(a, b));
	}
	vector<int> r;
	for(int i=0; i<n; i++) r.push_back(find(i));
	sort(r.begin(), r.end());
	r.erase(unique(r.begin(), r.end()), r.end());
	int rn=r.size();
	init(n+k);
	for(int i=0; i<n; i++){
		cin>>c[i];
		if(c[i]) unite(i, n+c[i]-1);
	}
	int ct1=n-k-ct0-(rn-1);
	if(ct1<0){
		cout<<-1<<endl;
		return 0;
	}
	sort(e, e+m);
	ll ans=0;
	vector<ll> use;
	for(int i=0; i<m; i++){
		if(!same(e[i].second.first, e[i].second.second)){
			unite(e[i].second.first, e[i].second.second);
			use.push_back(e[i].first);
		}
	}
	while(!use.empty()){
		if(ct1==0) break;
		use.pop_back();
		ct1--;
	}
	for(int i=0; i<use.size(); i++) ans+=use[i];
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5752
// #define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;


template<class T>
struct SegmentTree { // セグメント木

    const T INF = numeric_limits<T>::max();

    int n;
    int size;
    vector<T> mins, maxs;

    SegmentTree(int _n) {
        n = 1;
        size = _n;
        while(n < _n) n *= 2;
        mins.assign(n*2,INF);
        maxs.assign(n*2,-INF);
    }

    void update(int k, T a) { // val[k] = a;
        k += n-1;
        maxs[k] = mins[k] = a;
        while(k > 0) {
            k = (k-1) / 2;
            mins[k] = min(mins[k*2+1], mins[k*2+2]);
            maxs[k] = max(maxs[k*2+1], maxs[k*2+2]);
        }
    }

    T Min(int l, int r) { // 閉区間 [l,r] の最小値
        return _min(l, r+1, 0, 0, n);
    }
    T _min(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return mins[k];
        else {
            T vl = _min(a, b, k*2+1, l, (l+r)/2);
            T vr = _min(a, b, k*2+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }

    T Max(int l, int r) { // 閉区間 [l,r] の最大値
        return _max(l, r+1, 0, 0, n);
    }
    T _max(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return -INF;
        if(a <= l && r <= b) return maxs[k];
        else {
            T vl = _max(a, b, k*2+1, l, (l+r)/2);
            T vr = _max(a, b, k*2+2, (l+r)/2, r);
            return max(vl, vr);
        }
    }

    // 閉区間 [l,r] で x 以上の数が最初に現れるインデックスを返す
    // 無ければ一番後ろ (= r) を返す
    int lower_bound(int l, int r, T x) {
        while(abs(l-r) > 0) {
            int mid = (l+r) / 2;
            if(Max(l,mid) >= x) r = mid;
            else l = mid+1;
        }
        return Max(r,r) >= x ? l : r+1;
    }
};


int main(){

    int n, q;
    cin >> n >> q;

    SegmentTree<int> st(n);

    rep(i,n) {
        int a;
        cin >> a;
        st.update(i,a);
    }

    rep(i,q) {
        int t, a, b;
        cin >> t >> a >> b;
        if(t == 1) {
            a--;
            st.update(a,b);
        }
        if(t == 2) {
            a--; b--;
            cout << st.Max(a,b) << endl;
        }
        if(t == 3) {
            a--;
            cout << st.lower_bound(a,n-1,b) + 1 << endl;
        }
    }
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  ll ans = 0;
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  for (ll i = n-1; i >= 0; i--){
    if(a[i] % b[i] != 0){
      ll rest = a[i] % b[i];
      ans += b[i] - rest;
    }
    if(i > 0) a[i-1] += ans;
  }
  cout << ans << endl;
}

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

int main(){
    int n, count, var;
    cin >> n;
    count = 0;
    for (int x = 0; x < n; x++){
        cin >> var;
        if (var % 2 == 0 ){
            if (var % 3 != 0 && var % 5 != 0)
                count++;
                
        }
        
        
    }
    if (count)
        cout << "DENIED" << endl;
    else
        cout << "APPROVED" << endl;
    
}

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

int main(){
  ll a; cin >> a;
  string s;
  set<string> st;
  rep(i, a) {
      cin >> s;
      st.insert(s);
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 19204
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}




int main() {
	ll  N, X,an=0,m=999999;
	
	cin >>N>> X;
	rep(i, N) {
		ll p;
		cin >> p;
		X -= p;
		an++;
		m = min(m, p);
	};

	cout << an+X/m << endl;
	
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int m=0,f=0,r=0;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m==-1||f==-1){
			printf("F\n");
		}
		else if(m+f>=80){
			printf("A\n");
		}
		else if(m+f>=65){
			printf("B\n");
		}
		else if(m+f>=50){
			printf("C\n");
		}
		else if(m+f>=30){
			if(r>=50){
				printf("C\n");
			}
			else{
				printf("D\n");
			}
		}
		else{
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1012
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

class Vacation {
public:
        void solve(std::istream &in, std::ostream &out) {
                long long n;
                in >> n;
                long long arr[n][3];
                long long dp[n][3];
                memset(dp, 0, sizeof(dp));
                for (int i = 0; i < n; i++) {
                        in >> arr[i][0] >> arr[i][1] >> arr[i][2];
                        if (!i)
                                dp[i][0] = arr[i][0], dp[i][1] = arr[i][1], dp[i][2] = arr[i][2];
                        else {
                                dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
                                dp[i][1] = arr[i][1] + max(dp[i - 1][2], dp[i - 1][0]);
                                dp[i][2] = arr[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
                        }
                }
                out << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";
        }
};

int main() {
        Vacation solver;
        std::ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        std::istream &in(std::cin);
        std::ostream &out(std::cout);
        int t = 1;
        for (int i = 0; i < t; ++i) {
                solver.solve(in, out);
        }
        return 0;
}

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

using namespace std;

using ll = long long;

const int MX = 57;

int a[MX];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int mx = 0;
    for (int i = 1; i < n; i++) {
        if (abs(a[i]) > abs(a[mx])) {
            mx = i;
        }
    }
    if (a[mx] == 0) {
        cout << "0\n";
        return 0;
    }
    int v = a[mx];
    vector<pair<int, int> > ans;
    for (int i = 0; i < n; i++) {
        if (i != mx) {
            ans.emplace_back(mx, i);
        }
    }
    if (v > 0) {
        for (int i = 0; i + 1 < n; i++) {
            ans.emplace_back(i, i + 1);
        }
    } else {
        for (int i = n - 1; i > 0; i--) {
            ans.emplace_back(i, i - 1);
        }
    }
    cout << ans.size() << "\n";
    for (const auto& vv : ans) {
        cout << vv.first + 1 << " " << vv.second + 1 << "\n";
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int suma(int d);
int a;
char s[100000];
int t(int d){
  int ans=1;
  cin>>s;
  a--;
  while(a>=0){
    if(strlen(s)!=d)
      break;
    if(s[d-1]=='*')
      ans*=t(d+1);
    else if(s[d-1]=='+')
      ans*=suma(d+1);
    else{
      ans*=s[d-1]-'0';
      if(a==0)
        break;
      cin>>s;
      a--;
    }
  }
  return ans;
}

int suma(int d){
  int ans=0;
  a--;
  cin>>s;
  while(a>=0){
    if(strlen(s)!=d)
      break;
    if(s[d-1]=='*')
      ans+=t(d+1);
    else if(s[d-1]=='+')
      ans+=suma(d+1);
    else{
      if(strlen(s)!=d)
        break;
      ans+=s[d-1]-'0';
      if(a==0)
        break;
      cin>>s;
      a--;
    }
  }
  return ans;
}

int main(){
  int n;
  while(1){
    cin>>s;
    if(strlen(s)==1&&s[0]=='0')
      break;
    n=strlen(s);
    a=0;
    for(int i=0;i<n;i++){
      a*=10;
      a+=s[i]-'0';
    }
    a--;
    cin>>s;
    if(s[0]=='+')
      cout<<suma(2)<<endl;
    else if(s[0]=='*')
      cout<<t(2)<<endl;
    else
      cout<<s<<endl;
  }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int main(){
	int L;
	cin>>L;
	int N = 20;
	using E = tuple<int,int,int>;

	vector<E> es;
	rep(i,N-2){
		es.pb(E{i,i+1,0});
		es.pb(E{i,i+1,1<<i});
	}
	int off = 0;
	for(int i=N-2;i>=0;i--){
		while(L>=(1<<i)){
			es.pb(E{i,N-1,off});
			L -= 1<<i;
			off += 1<<i;
		}
	}
	cout<<N<<" "<<es.size()<<endl;
	for(E e: es){
		int x,y,w;
		tie(x,y,w) = e;
		cout<<x+1<<" "<<y+1<<" "<<w<<endl;
	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K,M;

inline void add(int &a,int b){
	a+=b;
	if(a>=M)a-=M;
}

int solve(int n,int k){
	vint dp(k+1);
	dp[0]=1;
	rep(i,n){
		int s=accumulate(all(dp),0ll)%M;
		rotate(dp.begin(),dp.begin()+k,dp.end());
		dp[0]=s;
	}
	return accumulate(all(dp),0ll)%M;
}

int dp[222][222][2];

signed main(){
	cin>>N>>K>>M;
	if(K%2==0){
		cout<<solve(N/2,K/2)*solve(N-N/2,K/2)%M<<endl;
		return 0;
	}

	N++;
	dp[0][0][0]=1;
	rep(i,N){
		rep(j,N){
			for(int k=0;i+k+1<=N;k++){
				if(k&1){
					if(k==1||1+K>=k+j){
						add(dp[i+k+1][j+k+1][0],dp[i][j][0]);
					}
					else{
						add(dp[i+k+1][k+1][1],dp[i][j][0]);
					}

					add(dp[i+k+1][j+k+1][1],dp[i][j][1]);
				}
				else{
					if(1+K>=k){
						add(dp[i+k+1][k][0],dp[i][j][0]);
					}
					if(1+K>=k+j){
						add(dp[i+k+1][k][0],dp[i][j][1]);
					}
				}
			}
		}
	}

	int ans=0;
	rep(i,N+1)add(ans,dp[N][i][0]);
	rep(i,1+K+1)add(ans,dp[N][i][1]);
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int n, q, m, d, dt, days[101];
    while(cin >> n >> q && n && q) {
        memset(days, 0, sizeof(days));
        for(int i = 0; i < n; i++) {
            cin >> d;
            for(int j = 0; j < d; j++) {
                cin >> dt;
                days[dt]++;
            }
        }
        int ans = 0;
        for(int i = 1; i <= 100; i++)
            if(days[i] >= q && days[i] > days[ans])
                ans = i;
        
        cout << ans << endl;
    }
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

typedef pair<int, int> P; 


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

    if(n <= 9) {
        cout << r + 100 * (10 - n) << endl;
    } else {
        cout << r << endl;
    }
    


    return 0;
}


Measured memory_bytes: 256
import heapq
N,M=map(int,input().split())
A=list(map(int,input().split()))
A=[-i for i in A]

heapq.heapify(A)
for i in range(M):
    a=-heapq.heappop(A)
    heapq.heappush(A,-(a//2))
print(-sum(A))

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

int main() {
    int64_t x;
    cin >> x;
    int64_t ans = 100, i = 0;
    while(ans < x){
        ans *= 1.01;
        i++;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    }

}

Measured memory_bytes: 50788
import java.util.Scanner;

/**
 *
 * @author mustafa
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long q = sc.nextLong();
        long h = sc.nextLong();
        long s = sc.nextLong();
        long d = sc.nextLong();
        long n = sc.nextLong();
        
        if (4 * q < s)
            s = 4 * q;
        else
            if (2 * h < s)
                s = 2 * h;
        
        if (n == 1)
        {
            System.out.println(s);
            return;
        }
        
        if (s * 2 < d)
        {
            System.out.println(n*s);
            return;
        }
        
        else
        {
            long k = n % 2;
            
            if (k == 0)
            {
                System.out.println((long)((n / 2) * d));
                return;
            }
            else
            {
                System.out.println((long)s + ((n - 1)/2) * d);
                return;
            }
        }
    }
    
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    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; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    REP(i,n)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    int count=0;
    REP(i,n)
    {
        if(a[i]==a[n-1])count++;
    }
    REP(i,n)
    {
        if(b[i]==a[n-1] && count>1)cout<<a[n-1]<<"\n";
        else if(b[i]==a[n-1])cout<<a[n-2]<<"\n";
        else cout<<a[n-1]<<"\n";
    }
  }
  return 0;
}

Measured memory_bytes: 4736
#include<iostream>
using namespace std;
int main()
{
	int n,i,state=1;
	cin>>n;
	int num[n+1];
	for(i=1;i<=n;i++)
		cin>>num[i];
	for(i=1;i<=n;i++)
		if(num[i]%2==0)
		{
			if(num[i]%3!=0&&num[i]%5!=0)
				state=0;
		}
	if(state==0)
		cout<<"DENIED"<<endl;
	else
		cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
n, T  = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
till = 0

for i in t:
    if i < till:
        temp = T - (till - i)
        ans += temp
        till += temp
    else:
        ans += T
        till = i + T

print(ans)

Measured memory_bytes: 85456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int calc_tree_center(int n, vector<vector<int>>& g, vector<int>&deg) {
  queue<int> q;
  rep(i,n) {
    if(deg[i]==1)
      q.push(i);
  }
  vector<bool> visited(n);
  while(q.size()>1) {
    int v = q.front();
    q.pop();
    visited[v]=true;
    for(auto&u : g[v]) {
      if(!visited[u])
	q.push(u);
    }
  }
  return q.front();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n;
  cin>>n;
  vector<vector<int>> g(n);
  vector<int> deg(n);
  rep(i,n-1) {
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<ll> c(n);
  rep(i,n)cin>>c[i];
  int s = calc_tree_center(n,g,deg);
  vector<bool> visited(n);
  vector<int> ord;
  queue<int> q;
  q.push(s);
  while(!q.empty()) {
    int v = q.front();
    ord.push_back(v);
    q.pop();
    visited[v]=true;
    for(auto& u : g[v]) {
      if(!visited[u])
	q.push(u);
    }
  }
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  vector<ll> cost(n);
  rep(i,n) {
    cost[ord[i]]=c[i];
  }
  fill(visited.begin(),visited.end(),false);
  q.push(s);
  ll ans=0;
  while(!q.empty()) {
    int v = q.front();
    q.pop();
    visited[v]=true;
    for(auto& u : g[v]) {
      if(!visited[u]) {
	q.push(u);
	ans+=cost[u];
      }
    }
  }
  cout << ans << endl;
  rep(i,n) {
    cout << cost[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1280
n, k, q = map(int, input().split())
score = [0 for i in range(n)]
for i in range(q):
  a = int(input())
  score[a - 1] += 1
for i in range(n):
  if q - score[i] >= k:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 51104
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

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

    for i in k..n {
        if a[i] > a[i-k] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


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

ll binpow(ll a,ll b ,ll m){
	a%=m;
	ll res(1);
	while(b){
		if(b&1)res=res*a % m;
		b>>=1;
		a=a*a % m;
	}
	return res;
}


 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.in","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	ll i,j,t,n;
   	cin>>n;
   	ll ans(0),m(1e9+7);
   	ans+=binpow(10LL,n,m);
   	ans+=binpow(8LL,n,m);
   	ans%=m;
   	ans-=2LL*binpow(9LL,n,m);
   	ans%=m;
   	ans=(ans+m)%m;
   	cout<<ans;
	
	
 
 
 
 
 
 
 
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  string S;
  cin>>S;
  rep(i,S.size()){
    if(i%2==0){
      if(S[i]=='L'){
        cout<<"No"<<endl;
        return 0;
      }
    }else{
      if(S[i]=='R'){
        cout<<"No"<<endl;
        return 0;
    }
  }
}

  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  int A[n][m] = {0};
  int B[m] = {0};
  for (int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      int r;
      cin >> r;
      A[i][j] = r;
    }
  }
 
  for(int j = 0; j < m; j++) {
    int r;
    cin >> r;
    B[j] = r;
  }
 
  for (int i = 0; i < n; i++) {
    int r = 0;
    for(int j = 0; j < m; j++) {
      r += A[i][j] * B[j];
    }
    cout << r << endl;
  }
 
}

Measured memory_bytes: 3136
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  while(ifs>>data)
int main (){
    string s;
    cin >> s;
    int n = s.size();
    REP(i,n){
        cout << "x";
    }
}

Measured memory_bytes: 256
a = int(input())
sr_1 = 'abcdefghijklmnopqrstuvrxyz'

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

print(num2alpha(a).lower())

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

const int SMAX = 1000;
const int MAX = 100000;
int main() { // O(max(NK, K^2))
	int N, K;
	cin >> N >> K;
	static int x, y, cum[SMAX][SMAX], map[SMAX][SMAX], wish = 0, BX[SMAX][SMAX], BY[SMAX][SMAX];
	char c;
	/* なんか動かなかった
	memset(map, 0, sizeof(char) * SMAX * SMAX);
	memset(BX, 0, sizeof(int) * SMAX * SMAX);
	memset(BY, 0, sizeof(int) * SMAX * SMAX);
	*/
	for (int i = 0;i < SMAX;i ++) for(int j = 0;j < SMAX;j ++) map[i][j] = 0;
	for (int i = 0;i < SMAX;i ++) for(int j = 0;j < SMAX;j ++) BX[i][j] = 0;
	for (int i = 0;i < SMAX;i ++) for(int j = 0;j < SMAX;j ++) BY[i][j] = 0;
	for (int i = 0;i < N;i ++) {
		cin >> x >> y >> c;
		x %= K << 1;
		y %= K << 1;
		if (x >= K) {
			x %= K;
			c = (c == 'B' ? 'W' : 'B');
		}
		if (y >= K) {
			y %= K;
			c = (c == 'B' ? 'W' : 'B');
		}
		map[y][x] += (c == 'B' ? 1 : -1);
		if (c == 'B') wish ++;
		for (int i = 0;i <= x;i ++) BX[y][i] += (c == 'B' ? -1 : 1);
		for (int i = x + 1;i < K;i ++) BX[y][i] += (c == 'B' ? 1 : -1);
		for (int i = 0;i <= y;i ++) BY[x][i] += (c == 'B' ? -1 : 1);
		for (int i = y + 1;i < K;i ++) BY[x][i] += (c == 'B' ? 1 : -1);
	}
	
	cum[0][0] = wish;
	for (int j = 1;j < K;j ++) {
		cum[0][j] = cum[0][j - 1] + BY[j - 1][0];
	}
	for (int i = 1;i < K;i ++) {
		cum[i][0] = cum[i - 1][0] + BX[i - 1][0];
		for (int j = 1;j < K;j ++) {
			cum[i][j] = cum[i][j - 1] + BY[j - 1][i];
		}
	}
	// デバッグ
	/*
	for (int i = K - 1;i >= 0;i --) {
		for (int j = 0;j < K;j ++) {
			cout << map[i][j];
		}
		cout << endl;
	}
	cout << endl;
	
	for (int i = K - 1;i >= 0;i --) {
		for (int j = 0;j < K;j ++) {
			cout << cum[i][j];
		}
		cout << endl;
	}
	cout << endl;
	*/
	// ここまで
	
	int ma = 0;
	for (int i = 0;i < K;i ++) {
		for (int j = 0;j < K;j ++) {
			ma = max(ma, cum[i][j]);
			ma = max(ma, N - cum[i][j]);
		}
	}
	cout << ma;
	return 0;
}
/*
K<=1000より、値が小さいことに着目。
まず、市松模様なので(x,y)=(x+K,y)=(x,y+K)が成り立つので、座標を圧縮できる
この時0<=xi<Kが成立できる
次に、この時x座標だけで考えると、ある座標を基準に黒/白を分断することが分かる
これはy座標についても同様
つまり、このある座標を求めれば良い
ちなみに、ある座標を含む右上と左下が黒、左上と右下が白な 問題例だと(4,2)
ある座標は全部でK^2通り考えられるので、それぞれについて何個の希望を満たせるかを考える
ここで、0からある座標までに点が何個あるかを求める二次元累積和があったとする
これを利用すれば、それぞれのある座標における希望の叶えられる数をO(1)で求められる
因みに反転系も考えるので、二次元累積和の値はN-その値も比較するようにね

ごめん考察直す時間ない、またあとで
*/

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int main(){

  int n; cin>>n;
  set<int>s;

  for(int i=0;i<n;i++)
 {
     int a;
     cin>>a;
     if(s.count(a)){
        cout<<"NO"<<endl;
        return 0;
        }
      s.insert(a);
  }

  cout<<"YES"<<endl;

 return 0;
 }


Measured memory_bytes: 12896