akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] l = new int[m];
		int[] r = new int[m];

		for(int i = 0; i < m; i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		
		Arrays.sort(l);
		Arrays.sort(r);
		
		int res = 0;
		
		for(int i = 1; i <= n; i++) {
			if(l[l.length-1] <= i && i <= r[0]) {
				res++;
			}
		}
		
		out.println(res);
		
 	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
	
	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 45720
import java.io.*;
class Main{
public static void main(String[] args){
String[] data = new String[3];
int output = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
while (true){
data = (br.readLine()).split(" ");
if (data[1].equals("?")) break;
switch(data[1]){
case "+":
output = Integer.parseInt(data[0]) + Integer.parseInt(data[2]);
break;
case "-":
output = Integer.parseInt(data[0]) - Integer.parseInt(data[2]);
break;
case "*":
output = Integer.parseInt(data[0]) * Integer.parseInt(data[2]);
break;
case"/":
output = Integer.parseInt(data[0]) / Integer.parseInt(data[2]);
break;
}
System.out.println(output);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
}

Measured memory_bytes: 24312
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t A, B, C, K;
    std::cin >> A >> B >> C >> K;

    int64_t magic_cnt = 0;
    while (A >= B)
    {
        B *= 2;
        magic_cnt++;
    }
    while (B >= C)
    {
        C *= 2;
        magic_cnt++;
    }
    
    std::string ans = magic_cnt <= K ? "Yes" : "No";
    std::cout << ans << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 3584
n = int(input())
s = input()

b = [0]
w = [0]

count_b = 0
count_w = 0
for i in range(n):
    if s[i] == "#":
        count_b += 1
    else:
        count_w += 1
    b.append(count_b)
    w.append(count_w)

ans = n
for i in range(n+1):
    ans = min(ans, b[i]+count_w-w[i])
print(ans)

Measured memory_bytes: 12792
#include<stdio.h>


#define N 8
#define E -1
#define NE 1

int R[N],C[N],dpos[2*N-1],dneg[2*N-1];

int x[N][N];
void init();
void print();
void recur(int);

int main(){
  int i,j,n,r,c;
  init();
  for(i=0;i<N;i++){
    for(j=0;j<N;j++) x[i][j] = 0; 
  }
  scanf("%d",&n);
  
    for(i=0;i<n;i++){
      scanf("%d",&r);
      scanf("%d",&c);
      x[r][c] = 1;
    }
  
    recur(0);
  

    return 0;
}

void init(){
  int i;
  for(i=0;i<N;i++){
    R[i] = E;
    C[i] = E;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=E;
    dneg[i]=E;
  }

}

void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(x[i][j]){
	if(R[i]!=j) return;
      }
    }

  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(R[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recur(int i){
  int j;
  if(i==N){
    print();
    return;
  }
  for(j=0;j<N;j++){
    if(NE == C[j] || NE == dpos[i+j]||NE ==dneg[i-j +N-1]) continue;
    R[i]=j;
    C[j]=NE;
    dpos[i+j]=NE;
    dneg[i-j+N-1]=NE;

    recur(i+1);
    R[i]=E;
    C[j]=E;
    dpos[i+j]=E;
    dneg[i-j+N-1]=N;
  }
  
}



Measured memory_bytes: 2104
display = []
while True:
    a = map(int,raw_input().split(' '))
    if a[0]==0 and len(a) ==1:
        for di in display:
            print di[0],di[1]
        break
    elif a[0]!=0 and len(a) ==1:
        n = a[0]
        score = [0,0]
        for i in range(n):
            x = map(int, raw_input().split(' '))
            if x[0] < x[1]:
                score[1] = score[1] + x[0]+x[1]
            elif x[0] > x[1]:
                score[0] = score[0] + x[0]+x[1]
            elif x[0] == x[1]:
                score[0] = score[0] +x[0]
                score[1] = score[1] +x[1]

        display.append([score[0],score[1]])

Measured memory_bytes: 4556
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 3e5 + 50, M = 2e6 + 50;
cs int INF = 1e9 + 7;
int n, S, T, fi[N], nxt[M], to[M], w[M], ec=1;
void adde(int x, int y, int z){
	nxt[++ec]=fi[x], fi[x]=ec, to[ec]=y, w[ec]=z;
	nxt[++ec]=fi[y], fi[y]=ec, to[ec]=x, w[ec]=0;
} int eu[N], ev[N], ct, d[N];
bool bfs(){
	queue<int> q; q.push(S); 
	memset(d,-1,sizeof(d)); d[S]=0;
	while(!q.empty()){
		int x=q.front(); q.pop();
		for(int e=fi[x],v;e;e=nxt[e]) if(w[e]){
			v=to[e]; if(d[v]==-1){
				d[v]=d[x]+1; q.push(v);
				if(v==T) return true;
			}
		}
	} return false;
}
int dfs(int u, int flw){
	if(u==T) return flw; int ans = 0;
	for(int e=fi[u],v;e;e=nxt[e])
	if(d[v=to[e]]==d[u]+1){
		int dt=dfs(v,min(w[e],flw));
		ans+=dt; flw-=dt;
		w[e]-=dt; w[e^1]+=dt; if(!flw) break;
	} if(flw) d[u]=-1; return ans;
}
int dinic(){ int flw = 0; while(bfs()) flw += dfs(S,INF); return flw; }
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n);
	for(int i=1,k,x; i<n; i++){
		scanf("%d",&k);
		for(int j=1; j<=k; j++) 
		scanf("%d",&x), adde(x,i+n,1);
	} S=0, T=n+n;
	for(int i=1; i<=n; i++) adde(S,i,1);
	for(int i=1; i<n; i++) adde(i+n,T,1);
	int flw = dinic();
	if(flw < n-1) return puts("-1"),0;
	
	static int tr[N];
	for(int i=n+1; i<n+n; i++)
	for(int e=fi[i];e;e=nxt[e]) 
	if(to[e]!=T&&w[e]) tr[i]=to[e];
	
	queue<int> q;
	for(int e=fi[S];e;e=nxt[e])
	if(w[e]) q.push(to[e]);
	
	static bool ban[N];
	while(!q.empty()){
		int x=q.front(); q.pop();
		for(int e=fi[x];e;e=nxt[e]) 
		if(to[e]!=S&&!ban[to[e]]){
			eu[to[e]-n]=x; ev[to[e]-n]=tr[to[e]];
			q.push(tr[to[e]]); ban[to[e]]=true; ++ct;
		}
	} if(ct<n-1) return puts("-1"),0;
	for(int i=1; i<n; i++) cout<<eu[i]<<" "<<ev[i]<<'\n';
	return 0;
}

Measured memory_bytes: 22148
#include <stdio.h>

int main()
{
	int K;
	int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	scanf("%d", &K);
	printf("%d\n", arr[K-1]);
	return 0;
}

Measured memory_bytes: 1700
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
    int n; //the number of teams
    cin >> n;
    int SC[n];
    for (int i = 1; i <= n; i++) {
        SC[i] = 0;
    }
    for (int i = 0; i < (n * n - n) / 2; i++) {
        int te1, te2; //team
        cin >> te1 >> te2;
        int sc1, sc2; //score
        cin >> sc1 >> sc2;
        if (sc1 > sc2) {
            SC[te1] += 3;
            SC[te2] += 0;
        } else if (sc1 == sc2) {
            SC[te1] += 1;
            SC[te2] += 1;
        } else {
            SC[te1] += 0;
            SC[te2] += 3;
        }
    }
    vector<pair<int, int> > v;
    for (int i = 1; i <= n; i++) {
        v.push_back(make_pair(SC[i], i));
    }
    sort(v.begin(), v.end());
    for (int i = n - 1; i >= 0; --i) {
        if (i != n - 1 && v[i].first == v[i + 1].first) {
            SC[v[i].second] = SC[v[i + 1].second];
        } else {
            SC[v[i].second] = n - 1 - i + 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << SC[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int a[N],diff[N];
int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=k;i++)
    {
        if(i==k)
        {
            diff[i]=n-a[i]+a[1];
        }
        else
            diff[i]=a[i+1]-a[i];
    }
    sort(diff+1,diff+k+1);
    int sum=0;
    for(int i=1;i<=k-1;i++)
        sum+=diff[i];
    cout<<sum<<endl;

}


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

int main() {
  int n,a,b; cin>>n>>a>>b;
  int sum=0,ans=0;
  int t=0;
  	for(int i=1;i<=n;i++){
      t=i;
      for(int j=0;j<5;j++){
      	sum+=t%10;
        t/=10;   
        }
     	if(a<=sum && sum<=b){
    		ans+=i;
        }
      sum=0;
   }
 	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

vecllong A;
vvecllong memoTurn1, memoTurn2;

llong search(llong left, llong right, int turn) {
    if(right - left == 1) {
        if(turn == 0) return A[left];
        else return -A[left];
    }
    if(turn == 0) {
        if(memoTurn1[left][right] != INF) return memoTurn1[left][right];
        llong ret = 0;
        ret = max({
            search(left + 1, right, 1) + A[left],
            search(left, right - 1, 1) + A[right - 1]
        });
        memoTurn1[left][right] = ret;
        return ret;
    } else {
        if(memoTurn2[left][right] != INF) return memoTurn2[left][right];
        llong ret = 0;
        ret = min({
            search(left + 1, right, 0) - A[left],
            search(left, right - 1, 0) - A[right - 1]
        });
        memoTurn2[left][right] = ret;
        return ret;
    }
};

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong N;
    cin >> N;

    A.resize(N, 0);
    FOR(i, N) {
        cin >> A[i];
    }

    memoTurn1.resize(N + 1, vecllong(N + 1, INF));
    memoTurn2.resize(N + 1, vecllong(N + 1, INF));

    llong ans = search(0, N, 0);
    cout << ans << endl;

    return 0;
}

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

int main()
{

  int hscore = 0 , fscore = 0 , rscore = 0 , n = 0;


  while(1){

    cin >> hscore >> fscore >> rscore;
    
    if( hscore == -1 && fscore == -1 && rscore == -1) break;
    if( hscore == -1 || fscore == -1){
      cout << "F" << "\n";
    } else if( hscore + fscore >= 80 &&  hscore + fscore < 101 ){
      cout << "A" << "\n";  
    } else if( hscore + fscore >= 65 && hscore + fscore < 80 ){
      cout << "B" << "\n";
    } else if( hscore + fscore >= 50 && hscore + fscore < 65 ){
      cout << "C" << "\n";
    } else if( hscore + fscore >= 30 && hscore + fscore < 50 && rscore >= 50 && rscore < 101){
      cout << "C" << "\n";
    } else if( hscore + fscore >= 30 && hscore + fscore < 50 ){
      cout << "D" << "\n";
    } else if( hscore + fscore < 30 && hscore + fscore >= 0  ){
	cout << "F" << "\n";
      }
      }
    
    
    
    return 0;
  }

Measured memory_bytes: 1120
#include <stdio.h>
#include <math.h>

int main()
{
	int b,c;
	int copy;
	int i;
	int digit;

	double x;

	// スペース区切りの整数の入力
	scanf("%d %d",&b,&c);

	/* 桁数を計算 */
	copy = c;
	digit = 0;
	while (copy != 0){
		copy = copy / 10;
		++digit;
	}

	i = 0;
	while (i < digit)
	{
		b *= 10;
		i++;
	}

	x = sqrt(b + c);

	if (ceil(x) != floor(x)) {
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <climits>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

void solve(void){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = A*X+B*Y;
    if (X < Y) {
        swap(A, B);
        swap(X, Y);
    }
    ans = min(ans, Y*2*C+(X-Y)*min(2*C,A));
    cout << ans << '\n';
}

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


Measured memory_bytes: 256
def make_divisors(n):
    """約数を全列挙する
    """
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


X = int(input())
divs = make_divisors(X)

# a = b+p
for p in divs:
    for b in range(-10000, 10000):
        a = b+p
        if a**5 - b**5 == X:
            print(a, b)
            exit()


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

int main() {
  string s;
  cin >>s;
  if(s[1]=='B') cout << "ARC" << endl;
  else if(s[1]=='R') cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3584
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

string S;

signed main(){

    in(S);
    out(stoi(S.substr(5,7))<=4?"Heisei":"TBD");

    return 0;
}


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

using namespace std;
using LL = long long;

constexpr int N = 2e3 + 5;

int n;
int dist[N], d[N];
vector< int> E[N];


void solve(int s) {
	//memset(dist, 0x3f3f3f3f, sizeof dist);
	vector< int> dist(n + 1, 0x3f3f3f3f);

	dist[s] = 0;
	queue < int> Q;
	Q.push(s);

	while (!Q.empty()) {
		int x = Q.front(); Q.pop();

		for (int y : E[x]) {
			if (dist[y] > dist[x] + 1) {
				dist[y] = dist[x] + 1;
				if (y > s) d[dist[y]]++;
				Q.push(y);
			}
		}
	}

	//for (int i = s + 1; s <= n; s++) cout << dist[i] << endl;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int x, y;
	cin >> n >> x >> y;


	for (int i = 1; i < n; i++) {
		E[i].push_back(i + 1);
		E[i + 1].push_back(i);
	}
	E[x].push_back(y);
	E[y].push_back(x);

	for (int i = 1; i < n; i++) {
		solve(i);
	}

	for (int i = 1; i < n; i++) cout << d[i] << "\n";
}

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

int main() {
  string s;
  cin >> s;

    if( s=="a" || s=="i" || s=="u" || s=="o" || s=="e"){
      
    cout << "vowel" << endl;
    }
      
      else  {
        cout << "consonant" << endl;
        
}
}
  
  
  
  


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 210000;

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

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

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

int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

int N;
int C[200010];

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

	COMinit();

	cin >> N;
	rep(i, 0, N)cin >> C[i];

	sort(C, C + N);

	int ans = 0;
	rep(i, 0, N)
	{
		int res;

		if (i < N - 1)
		{
			res = (N - i - 1)*modpow(2, N - i - 2);
			res %= MOD;
			res += modpow(2, N - i - 1);
			res %= MOD;
			res *= modpow(2, i);
			res %= MOD;
		}
		else
		{
			res = modpow(2, i);
		}

		ans += res * C[i];
		ans %= MOD;
	}
	ans *= modpow(2, N);
	ans %= MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6784
import collections

rank = {'S': 0, 'H': 1, 'C': 2, 'D': 3}
Card = collections.namedtuple('Card', ['suit', 'num'])
all_cards = {Card(suit, str(num)) for suit in ['S', 'H', 'C', 'D'] for num in range(1, 14)}

n = int(input())
cards = {Card(*input().split()) for _ in range(n)}
lost = sorted(all_cards - cards, key=lambda x: (rank[x.suit], int(x.num)))
if lost:
    print('\n'.join('%s %s' % (suit, num) for suit, num in lost))

Measured memory_bytes: 6740
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n) \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)   \
    sort(all(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
    return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto& x : v) is >> x;
    return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
    bool t = 0;
    for (const T& x : v.first) {
        if (t) os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    lint n, x;
    cin >> n >> x;
    vector<lint> a(n), b(n);
    cin >> a;
    b = a;

    lint ans = accumulate(all(a), 0LL);
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n; j++) {
            a[j] = min(a[j], b[(j-i+n)%n]);
        }
        ans = min(ans, accumulate(all(a), i*x));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>


int main() {
	int a; std::string s; std::cin >> a >> s;
	if (a >= 3200) std::cout << s << std::endl;
	else std::cout << "red" << std::endl;
}



Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int n;
	cin >> n;
	string acl = "ACL";
	string ans;

	for (int i = 0; i < n; i++) {
		ans += acl;
	}

	printf("%s", ans.c_str());

	return 0;
}

Measured memory_bytes: 3660
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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(){ 
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m){
        int x, y, z; cin >> x >> y >> z; x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    
    vector<bool> seen(n, false);
    queue<int> que;
    int res = 0;
    rep(i, n){
        if(seen[i]) continue;
        seen[i] = true; res++;
        que.push(i);
        while(!que.empty()){
            int v = que.front(); que.pop();
            for(int e: G[v]){
                if(seen[e]) continue;
                seen[e] = true;
                que.push(e);
            }
        }
    }
    cout << res << ln;
}

Measured memory_bytes: 6520
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    string s, t;
    cin >> s >> t;
    int slen, tlen;
    slen = s.size(); tlen = t.size();
    vector<vector<int>> dp(slen+1, vector<int>(tlen+1, 0));
    vector<vector<P>> trace(slen+1, vector<P>(tlen+1));
    //vector<bool> sused(slen, false);
    //vector<bool> tused(tlen, false);

    for(int i=1; i<slen+1; i++){
        for(int j=1; j<tlen+1; j++){
            if(dp[i][j-1]>=dp[i-1][j]){
                dp[i][j] = dp[i][j-1];
                trace[i][j] = P(i, j-1);
            } else{
                dp[i][j] = dp[i-1][j];
                trace[i][j] = P(i-1,j);
            }


            if(s[i-1]==t[j-1] && dp[i-1][j-1]+1>=dp[i][j]) {
                //sused[i-1] = true;
                //tused[j-1] = true;
                dp[i][j] = dp[i-1][j-1] + 1;
                trace[i][j] = P(i-1, j-1);
                
            } 
        }
    }

    int i = slen;
    int j = tlen;
    
    vector<char> ans;
    while(i!=0 && j!=0){
        int inext = trace[i][j].first;
        int jnext = trace[i][j].second;
        if(dp[i][j]!=dp[inext][jnext]){
            ans.push_back(s[i-1]);
        }
        i = inext;
        j = jnext;
    }

    if(ans.size()==0) cout << ' ' << endl;
    else {
        for(int i=ans.size()-1; i>=0; i--){
            cout << ans[i];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 105984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

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

ans=min(a+b,min(b+c,a+c));
cout << ans<< endl;
return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0;i < n;i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		int ret = 0;
		List<Integer> list = new ArrayList<>();
		int s = 0;
		for (int i = 0;i < n;i++) {
			int tmp = a[i];
			if (list.size()==0) {
				s = tmp;
				list.add(tmp);
			} else if (tmp<=s+k&&list.size()<c) {
				list.add(tmp);
			} else {
				list.clear();
				list.add(tmp);
				s = tmp;
				ret++;
			}
		}

		if (list.size()>0) ret++;

		System.out.println(ret);
	}
}

Measured memory_bytes: 52816
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 r,g,b,n;

int main() {
  cin >> r >> g >> b >> n;
  i64 cnt = 0;
  for(int i = 0;i * r <= n;i++) {
    for(int j = 0;i * r + j * g <= n;j++) {
      if((n - i * r - j * g) % b == 0) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
from copy import deepcopy

n,m = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(m)]

graph = [[] for i in range(n)]
for a,b in AB:
    a,b = a-1,b-1
    graph[a].append(b)
    graph[b].append(a)

path = [0]*n
path[0] = 1
# print(graph)
# print(path)

def func(i,path,ans):
    # print(i,path)
    if path.count(1) == n:
        return ans+1
    flag = 1
    for g in graph[i]:
        if path[g] == 0:
            flag = 0
            next_path = deepcopy(path)
            next_path[g] = 1
            ans = func(g,next_path,ans)
    return ans
ans = func(0,path,0)
print(ans)

Measured memory_bytes: 3572
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        
        int N = nextInt();
        
        String S= ("" + N);
        String s = S.substring(S.length()-1);

        if(s.equals("3")){
            System.out.println("bon");
        } 
        else if(s.equals("0")||s.equals("1")|s.equals("6")||s.equals("8")){
            System.out.println("pon");
        } 
        else{
            System.out.println("hon");
        }


    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

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

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

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

int main()
{
  string S,T ;
  cin>>S>>T ;
  
  int count=0 ;
  int size=S.size() ;
  while(count<=size){
    int front=S.at(size-1) ;
    for(int i=0;i<size;i++){
      int tmp=S.at(i) ;
      S.at(i)=front ;
      front=tmp ;
    }
    if(S==T){
      cout<<"Yes"<<endl ;
      return 0 ;
    }
    count++ ;
  }
  cout<<"No"<<endl ;
  return 0 ;
}

Measured memory_bytes: 256
from collections import defaultdict
import collections
n, m = map(int, input().split())
mydic = defaultdict(set)
for i in range(m):
    ai, bi = map(int, input().split())
    mydic[ai].add(bi)
    mydic[bi].add(ai)
queque = collections.deque()
visited = [0] * (n + 1)
ans = 0
for i in range(1, n+1):
    if not visited[i]:
        temp = 1
        queque.append(i)
        temp = 1
        while queque:
            j = queque.popleft()
            visited[j] = 1
            for k in mydic[j]:
                if visited[k] == 0:
                    temp += 1
                    visited[k] = 1
                    queque.append(k)
        ans = max(ans, temp)
    else:
        continue            
print(ans)

Measured memory_bytes: 82228
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;

int main(){
	int n,m;
	cin >> n;
	list<int> intlist;
	list<int>::iterator it = intlist.begin();
	string str;
	
	for(int i = 0; i < n; i++){
		cin >> str;
		if(str == "deleteFirst"){
			intlist.pop_front();
			continue;
		}
		if(str == "deleteLast"){
			intlist.pop_back();
			continue;
		}
		cin >> m;
		if(str == "insert"){
			intlist.push_front(m);
		}
		if(str == "delete"){
			it = find(intlist.begin(),intlist.end(),m);
			if( it != intlist.end()) intlist.erase(it);
		}
	}

	it = intlist.begin();
	while(it != intlist.end()){
		if(it != intlist.begin()) cout << " ";
		cout << *it;
		++it;
	}
	cout << endl;
	return 0;
}		

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

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	ll n; cin >> n; ll a[5];
	Rep(i, 5){
		a[i] = 0;
	}
	Rep(i, n){
		string s; cin >> s;
		if(s[0] - 'M' == 0){
			a[0] += 1;
		}else if(s[0] - 'A' == 0){
			a[1] += 1;
		}else if(s[0] - 'R' == 0){
			a[2] += 1;
		}else if(s[0] - 'C' == 0){
			a[3] += 1;
		}else if(s[0] - 'H' == 0){
			a[4] += 1;
		}
	}
	ll ans = 0;
	Rep(i, 5){
		For(j, i+1, 5){
			For(k, j+1, 5){
				ans += a[i] * a[j] * a[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

n, w, d = map(int, input().split())
while not n == w == d == 0:
    if n == 0:
        print(w * d)
    else:
        num_list = [[0, 0, w, d]]
        for _ in range(n):
            p, s = map(int, input().split())
            vert = width = -1
            x1, y1, x2, y2 = num_list.pop(p - 1)
            temp_vert = y2 - y1
            temp_width = x2 - x1
            s %= (temp_width + temp_vert) * 2
            for k in range(10 ** 9):
                if k % 4 == 0:
                    if s <= temp_width:
                        width = s
                        break
                    else:
                        s -= temp_width
                elif k % 4 == 1:
                    if s <= temp_vert:
                        vert = s
                        break
                    else:
                        s -= temp_vert
                elif k % 4 == 2:
                    if s <= temp_width:
                        width = temp_width - s
                        break
                    else:
                        s -= temp_width
                else:
                    if s <= temp_vert:
                        vert = temp_vert - s
                        break
                    else:
                        s -= temp_vert
            if width != -1:
                grid1 = [x1, y1, x1 + width, y2]
                area1 = (width - x1 + x1) * (y2 - y1)
                grid2 = [x1 + width, y1, x2, y2]
                area2 = (x2 - width - x1) * (y2 - y1)
            else:
                grid1 = [x1, y1, x2, y1 + vert]
                area1 = (x2 - x1) * (vert + y1 - y1)
                grid2 = [x1, y1 + vert, x2, y2]
                area2 = (x2 - x1) * (y2 - vert - y1)
            num_list.append(grid1 if area1 <= area2 else grid2)
            num_list.append(grid2 if area1 <= area2 else grid1)
        print(" ".join(list(map(str, sorted([abs((i[2] - i[0]) * (i[3] - i[1])) for i in num_list])))))
    n, w, d = map(int, input().split())


Measured memory_bytes: 8992
#include<stdio.h>
int main(void){
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(( x >= r )&&( x + r <= W )&&( y >= r)&&( y + r <= H )){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 1820
n,m,x=map(int,input().split())
l=[]
for i in range(n):
  s=list(map(int,input().split()))
  l.append(s)
ans=12*(10**5)
#print(l)
import itertools
now=0
oko=0
com=[i for i in range(n)]
while now<=n:
  now+=1
  level=[0 for j in range(0,m+1)]
  for i in itertools.combinations(com, now):
    level=[0 for j in range(m+1)]
    money=0
    #print(i)
    for h in i:
      #print(h,"h")
      money+=l[h][0]
      for k in range(1,m+1):
        level[k]+=l[h][k]
    jud=0
    for ii in level:
      if ii>=x:
        jud+=1
    if jud==m:
      oko+=1
      #print("ok",i)
      ans=min(ans,money)
if oko==0:
  print("-1")
else:
  print(ans)

Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace  std;
const int maxn = 1e5+5;
const int maxm = 1e5+5;
const int mod  = 1e9+7;
const int inf  = 0x3f3f3f3f;
//typedef __int128  II;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n,a[110];
int main()
{
    scanf( "%d" , &n ); for( int i=1 ; i<=n ; i++ ) scanf( "%d" , &a[i] );
    int tot = 0,dif = inf,ans; for( int i=1 ; i<=n ; i++ ) tot += a[i];
    for( int i=1 ; i<=n ; i++ )
    {
        if ( abs(tot-a[i]*n)<dif )
        {
            ans = i-1; dif = abs(tot-a[i]*n);
        }
    }
    printf( "%d\n" , ans );
    return  0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    long long S;
    cin >> S;
    long long x1 = 0, y1 = 0, x2 = 1000000000, y2 = 1, x3, y3;
    x3 = (x2 - S % x2) % x2;
    y3 = (S + x3) / x2;
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}

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

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

  if(b == 1){
    cout << '0' << endl;
    return 0;
  }
  
  int total = a;
  for(int i = 1; ; i++){
    if(total >= b){
      cout << i << endl;
      break;
    }
    total += (a-1);
  }

  return 0;

}


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

int main(){
  int n;
  cin >> n;
  map<string,int> cnt;
  rep(i,n){
  	string s;
    cin >> s;
    cnt[s]++;
  }
  for(string s:{"AC","WA","TLE","RE"}){
    cout << s << " x " << cnt[s] << endl;
  }
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 5005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
struct node {
	int to,next;
}E[MAXN * 2];
int head[MAXN],sumE;
bool vis[MAXN][MAXN][2],used[MAXN][2];
int64 dp[MAXN][MAXN][2],A[MAXN],g[MAXN][2];
int N,siz[MAXN],ans;
void add(int u,int v) {
	E[++sumE].to = v;
	E[sumE].next = head[u];
	head[u] = sumE;
}
void dfs(int u,int fa) {
	if(A[u] < 0) {
		vis[u][0][1] = 1;dp[u][0][1] = A[u];
	}
	if(A[u] > 0) {
		vis[u][0][0] = 1;dp[u][0][0] = A[u];
	}
	for(int i = head[u] ; i ; i = E[i].next) {
		int v = E[i].to;
		if(v != fa) {
			dfs(v,u);
		}
	}
	memset(used,0,sizeof(used));
	siz[u] = 1;
	for(int i = head[u] ; i ; i = E[i].next) {
		int v = E[i].to;
		if(v != fa) {
			for(int j = 0 ; j <= siz[u] + siz[v] ; ++j) used[j][0] = used[j][1] = 0;
			for(int j = 0 ; j <= siz[u] ; ++j) {
				for(int a = 0 ; a <= 1 ; ++a) {
					if(!vis[u][j][a]) continue;
					for(int h = 0 ; h <= siz[v] ; ++h) {
						for(int b = 0 ; b <= 1 ; ++b) {
							if(!vis[v][h][b]) continue;
							if(!used[j + h][a | b]) {
								g[j + h][a | b] = dp[u][j][a] + dp[v][h][b];
								used[j + h][a | b] = 1;
							}
							else g[j + h][a | b] = min(g[j + h][a | b],dp[u][j][a] + dp[v][h][b]);
						}
					}
				}
			}
			for(int j = 0 ; j <= siz[u] + siz[v] ; ++j) {
				for(int a = 0 ; a <= 1 ; ++a) {
					vis[u][j][a] = used[j][a];
					dp[u][j][a] = g[j][a];
				}
			}
			siz[u] += siz[v];
		}
	}
	if(fa) {
		for(int j = siz[u] ; j >= 0 ; --j) {
			if(vis[u][j][1] && dp[u][j][1] < 0) {dp[u][j + 1][0] = 0;vis[u][j + 1][0] = 1;}
			if(vis[u][j][0]) {dp[u][j + 1][0] = 0;vis[u][j + 1][0] = 1;}
		}
	}
	else {
		for(int j = 0 ; j <= siz[u] ; ++j) {
			if(vis[u][j][1] && dp[u][j][1] < 0) {ans = j;break;}
			if(vis[u][j][0]) {ans = j;break;}
		}
	}
}
void Solve() {
	read(N);
	for(int i = 1 ; i <= N ; ++i) read(A[i]);
	int u,v;
	for(int i = 1 ; i < N ; ++i) {
		read(u);read(v);
		add(u,v);add(v,u);
	}
	dfs(1,0);
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 440448
#include<iostream>
#include<cstdio>
using namespace std;
int a[1000000],b[1000000];
int main()
{
	int i,j,k,m=0,n=0;
	for(i=2;i<=1000000;i++)
	{
		if(a[i]!=1)
		{
			j=i*2;
			while(j<1000000){a[j]=1;j=j+i;}
			n++;
		}
		b[i]=n;
	}
	while(cin>>n)
	{
		cout<<b[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 10872
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		var a=sc.Ia;
		int m=1<<n;
		var dp=new int[m+1][];
		var ans=new long[m-1];
		for(int i = 1,j=1;i<m;i++) {
			dp[i]=new int[2];
			dp[i][0]=i;
			Array.Sort(dp[i],(u,v)=>a[v]-a[u]);
			if(i==j){
				j<<=1;
			}
			else{
				for(int k = 1;k<=i;k<<=1) {
					if((i&k)==k){
						if(a[dp[i][0]]<a[dp[i^k][0]]){
							dp[i][1]=dp[i][0];
							dp[i][0]=dp[i^k][0];
							if(a[dp[i][1]]<a[dp[i^k][1]]){
								dp[i][1]=dp[i^k][1];
							}
						}
						else if(a[dp[i][1]]<a[dp[i^k][0]]&&dp[i][0]!=dp[i^k][0]){
							dp[i][1]=dp[i^k][0];
						}
					}
				}
			}
			ans[i-1]=a[dp[i][0]];
			ans[i-1]+=a[dp[i][1]];
			if(i!=1){ans[i-1]=Max(ans[i-1],ans[i-2]);}
		}
		Console.WriteLine("{0}",String.Join("\n",ans));
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 61728
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

d = ni()
c = na()
s = nan(d)
t = nin(d)

last = [0] * 26

ans = 0
for i in range(d):
    sa = s[i]
    cur = t[i]
    cur -= 1
    ans += sa[cur]
    last[cur] = (i + 1)
    for j in range(26):
        ans -= c[j] * ((i + 1) - last[j])
    print(ans)

Measured memory_bytes: 9316
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n = int(input())
    aa = LI()
    #どこかで2つに区切って、左の上位n項の和と右の下位n項の和を求め、その差を最大にすればいい
    # 左からn+i項のうち上位n項の和をmax_Lに記録
    max_L = [0] * (n + 1)
    hp = []
    s = 0
    for a in aa[:n]:
        heappush(hp, a)
        s += a
    max_L[0] = s
    for i, a in enumerate(aa[n:2 * n], 1):
        if a > hp[0]:
            s -= heappop(hp)
            s += a
            heappush(hp, a)
        max_L[i] = s

    # 右からn+i項のうち下位n項の和をmin_Rに記録
    min_R = [0] * (n + 1)
    hp = []
    s = 0
    for a in aa[:-n - 1:-1]:
        heappush(hp, -a)
        s += a
    min_R[n] = s
    for i, a in enumerate(aa[-n - 1:-2 * n - 1:-1]):
        if a > hp[0]:
            s -= -heappop(hp)
            s += a
            heappush(hp, -a)
        min_R[n - 1 - i] = s
    # print(max_L)
    # print(min_R)
    #各区切り方にのうち、左ー右が最大のものが答え
    print(max(s0 - s1 for s0, s1 in zip(max_L, min_R)))

main()


Measured memory_bytes: 39644