akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            long a = in.nextLong();
            long b = in.nextLong();
            if (b - a + 1 >= 2019){
                out.println(0);
                return;
            }
            long l = a % 2019;
            long r = b % 2019;
            if (r < l){
                out.println(0);
                return;
            }
            long min = (l * (l + 1)) % 2019;
            for (long i = l; i < r; i++) {
                for (long j = i + 1; j <= r; j++) {
                    if ((i * j)  % 2019 < min){
                        min = (i * j)  % 2019;
                    }
                }
            }
            out.println(min);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


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

int N;
i64 A,B;
i64 K;

typedef long long i64;

i64 MOD = 998244353;

// Eucli
i64 inv_mod(i64 a, i64 m = MOD) {
  i64 b, x, u, q, abs_m, tmp;

  abs_m = (m < 0) ? -m : m;
  b = m;
  x = 1;
  u = 0;
  while (b > 0) {
    q = a / b;
    tmp = u;
    u = x - q * u;
    x = tmp;
    tmp = b;
    b = a - q * b;
    a = tmp;
  }

  return (x < 0) ? abs_m + x : x;
}

i64 fact[303030];
i64 inv_fact[303030];

void init(){
  fact[0] = 1;
  rep(i,1,300000){
    fact[i] = (fact[i - 1] * i)  % MOD;
  }

  inv_fact[300000] = inv_mod(fact[300000]);
  for(int i = 300000 - 1;i >= 0;i--){
    inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % MOD;
  }
}

i64 nCr(int n, int r) {
  return (fact[n] * inv_fact[r] % MOD * inv_fact[n - r] % MOD) % MOD;
}

//重複組み合わせ
i64 nHr(int n, int r) { return (nCr(n + r - 1, r)) % MOD; }

int main(){
  init();
  cin >> N >> A >> B >> K;

  i64 ans = 0;

  for(i64 i = 0;i <= N && i * A <= K;i++){
    i64 re = K - i * A;
    i64 j = re / B;
    if(re % B != 0) continue;
    if(j > N) continue;
    ans = (ans + ((nCr(N,i) * nCr(N,j)) % MOD)) % MOD;
  }

  cout << ans << endl;
}



Measured memory_bytes: 4992
#include <stdio.h> 
int main() {
int a, b, c, d, k, j, l;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
if (a > c) {
k = a - c;
} else {
k = c - a;
} if (a > b) {
j = a - b;
} else {
j = b - a;
} if (b > c) {
l = b - c;
} else {
l = c - b;
}  
if (k <= d) {
printf("Yes\n");
} else if (j <= d && l <= d) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int k = 1;
  while(n > k*(k-1)/2){
      k++;
  }
  if(n<k*(k-1)/2){
    printf("No\n");
  }else{
    printf("Yes\n%d\n",k);
    int i;
    for(i=0;i<k;i++){
      printf("%d",k-1);
      int j;
      for(j=0;j<k-1;j++){
        if(i>j){
          printf(" %d",n-(k-j)*(k-j-1)/2+i-j);
        }else{
          printf(" %d",(n+1)-(k-i)*(k-i-1)/2+j-i);
        }
      }
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>

using namespace std;


int main(void){
  int n, max=0, now=0;
  string s;
  cin >> n >> s;

  for (int i=0; i<n; i++) {
    if (s[i]=='I') now++;
    else now--;
    if (max<now) max=now;
  }

  cout << max << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

const ll INF=1e18;
const int MAX_N=114514;
const int MAX_E=214514;

struct UnionFind{
	vector<int> par;
	vector<int> rank;

	UnionFind(int n=1){
		init(n);
	}

	// n要素で初期化
	void init(int n=1){
		par.resize(n);
		rank.resize(n);
		REP(i, n){
			par[i]=i;
			rank[i]=0;
		}
	}

	// xの根を求める
	int find(int x){
		if(par[x]==x){
			return x;
		}
		else{
			return par[x]=find(par[x]);
		}
	}

	// xとyが属する集合を併合
	bool unite(int x, int y){
		x=find(x);
		y=find(y);
		if(x==y){
			return false;
		}
		if(rank[x]<rank[y]){
			par[x]=y;
		}
		else{
			par[y]=x;
			if(rank[x]==rank[y]){
				++rank[x];
			}
		}
		return true;
	}

	// xとyが同じ集合に属するか判定
	bool is_same(int x, int y){
		return find(x)==find(y);
	}
};

struct edge{
	int u;
	int v;
	int cost;
};

int root[MAX_N], depth[MAX_N];

edge es[MAX_E];
int V, E;

void add_edge(int u, int v, int cost){
	edge e;
	e.u=u;
	e.v=v;
	e.cost=cost;
	es[E++]=e;
	return;
}

bool comp(const edge& e1, const edge& e2){
	return e1.cost<e2.cost;
}

ll kruskal(){
	sort(es, es+E, comp);
	UnionFind uf(V);
	ll res=0;
	REP(i, E){
		edge e=es[i];
		if(!uf.is_same(e.u, e.v)){
			uf.unite(e.u, e.v);
			res+=e.cost;
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	pii x[114514], y[114514];
	cin>>n;
	V=n;
	REP(i, n){
		cin>>x[i].first>>y[i].first;
		x[i].second=i;
		y[i].second=i;
	}
	sort(x, x+n);
	REP(i, n-1){
		add_edge(x[i].second, x[i+1].second, x[i+1].first-x[i].first);
	}
	sort(y, y+n);
	REP(i, n-1){
		add_edge(y[i].second, y[i+1].second, y[i+1].first-y[i].first);
	}
	cout<<kruskal()<<'\n';
	return 0;
}


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

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

	sort(a.begin(), a.end(), greater<int>());

	int idx = 0;
	int sumAlice = 0, sumBob = 0;
	while(true) {
		if(idx < N) {
			sumAlice += a[idx++];
		} else {
			break;
		}
		if(idx < N) {
			sumBob += a[idx++];
		} else {
			break;
		}
	}
	printf("%d\n", sumAlice - sumBob);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,K;
  cin>>A>>B>>K;
  int sum=0;
  int ans;
  for(int i=min(A,B); ;i--){
  if(A%i==0 && B%i==0){
    sum++;
    ans=i;}
    if(sum==K) break;
  }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int s[26],t[26];
    for(int i=0;i<26;i++){
        s[i]=-1;
        t[i]=-1;
    }
    string ss,tt;
    cin>>ss>>tt;
    for(int i=0;i<ss.size();i++){
        if((s[ss[i]-'a']!=-1 && s[ss[i]-'a']!=tt[i]-'a')||(t[tt[i]-'a']!=-1 && t[tt[i]-'a']!=ss[i]-'a')){
            cout<<"No"<<endl;
            return 0;
        }
        else {
            s[ss[i]-'a']=tt[i]-'a';
            t[tt[i]-'a']=ss[i]-'a';
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 776
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

int n,m,c=0;double tot=0.0;cin>>n>>m;bool isfail=true;
int arr[102];
for(int i=1;i<=n;++i)
{
	cin>>arr[i];

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

	tot+=arr[j];
	}
for(int y=1;y<=n;y++)
{
   if(arr[y]>=(tot/(4*m)))
   {
	c++;
   }
   if(c==m){
   	cout<<"Yes"<<endl;
   	isfail=false;
   	break;
   }
}if(isfail==true)
	cout<<"No"<<endl;















    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int64_t h, w;
    cin >> h >> w;

    int64_t best_diff = std::numeric_limits<int64_t>::max();

    // pattern 1
    {
        const int64_t dh = (h + 2) / 3 - h / 3;
        best_diff = min(best_diff, dh * w);
    }

    // pattern 2
    {
        const int64_t dw = (w + 2) / 3 - w / 3;
        best_diff = min(best_diff, dw * h);
    }

    // pattern 3
    {
        vector<int64_t> cand{ w / 3, w / 3 + 1 };
        for (auto cw : cand)
        {
            vector<int64_t> area_cand;
            area_cand.push_back(h * cw);
            area_cand.push_back((w - cw) * (h / 2));
            area_cand.push_back((w - cw) * (h - h / 2));
            sort(area_cand.begin(), area_cand.end());
            best_diff = min(best_diff, area_cand[2] - area_cand[0]);
        }
    }

    // pattern 3
    {
        vector<int64_t> cand{ h / 3, h / 3 + 1 };
        for (auto ch : cand)
        {
            vector<int64_t> area_cand;
            area_cand.push_back(w * ch);
            area_cand.push_back((h - ch) * (w / 2));
            area_cand.push_back((h - ch) * (w - w / 2));
            sort(area_cand.begin(), area_cand.end());
            best_diff = min(best_diff, area_cand[2] - area_cand[0]);
        }
    }

    cout << best_diff << endl;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
count = 0
i = 1
zero = 0
rem = 0
if k % 2 == 0:
    while i <= n:
        if i % k == 0:
            zero += 1
        elif i % int(k/2) == 0:
            rem += 1
        i += 1
    print(zero ** 3 + rem ** 3)
else:
    while i <= n :
        if i % k == 0:
            count += 1
        i += 1
    print(count ** 3)

Measured memory_bytes: 3064
N = int(input())
h = []
for i in range(N):
    abc = [int(x) for x in input().split()]
    h.append(abc)
aDP = [0]*N
bDP = [0]*N
cDP = [0]*N
aDP[0] = h[0][0]
bDP[0] = h[0][1]
cDP[0] = h[0][2]
for i in range(1,N):
    aDP[i] = h[i][0] + max(bDP[i-1],cDP[i-1])
    bDP[i] = h[i][1] + max(aDP[i-1],cDP[i-1])
    cDP[i] = h[i][2] + max(bDP[i-1],aDP[i-1])
print(max(aDP[N-1],bDP[N-1],cDP[N-1]))

Measured memory_bytes: 36212
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

const int MAX_N = 2e5;
int N;
int a[MAX_N+5], b[MAX_N+5];
int ca[MAX_N+5], cb[MAX_N+5];

int main(){
    scanf("%d", &N);
    for(int i=0;i<N;i++) scanf("%d", &a[i]);
    for(int i=0;i<N;i++) scanf("%d", &b[i]);

    ll ans = 0, p = 1;
    for(int i=0;i<30;i++){
        for(int j=0;j<N;j++){
            ca[j] = a[j] % (p<<1);
            cb[j] = b[j] % (p<<1);
        }

        sort(cb, cb+N);

        int cnt = 0;
        for(int j=0;j<N;j++){
            int d1 = distance(lower_bound(cb, cb+N, p-ca[j]), lower_bound(cb, cb+N, 2*p-ca[j]));
            int d2 = distance(lower_bound(cb, cb+N, 3*p-ca[j]), lower_bound(cb, cb+N, 4*p-ca[j]));
            cnt ^= (d1+d2) % 2;
        }

        if(cnt) ans += p;
        p <<= 1;
    }

    printf("%lld", ans);
    return 0;
}

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

int main(){
while(1){
	int a,b,c,n,p[1002],q[1002],r[1002],s[1002],Q[302];
	for(int i=0;i<302;i++)Q[i]=2;
	scanf("%d%d%d",&a,&b,&c);
	if(a==0&&b==0&&c==0)break;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&p[i],&q[i],&r[i],&s[i]);
		if(s[i]==1){Q[p[i]]=1; Q[q[i]]=1; Q[r[i]]=1;}
	}
	for(int i=0;i<n;i++){
		if(s[i]==0){
			if(Q[p[i]]==1&&Q[q[i]]==1)Q[r[i]]=0;
			if(Q[p[i]]==1&&Q[r[i]]==1)Q[q[i]]=0;
			if(Q[r[i]]==1&&Q[q[i]]==1)Q[p[i]]=0;
		}
	}
	for(int i=1;i<=a+b+c;i++){
		printf("%d\n",Q[i]);
	}
}
}

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

ll X;

int main(){
    while(scanf("%lld", &X)!=EOF){
        ll lo=1, hi=1000000000;
        while(lo<hi){
            ll mid=lo+(hi-lo)/2; 
            if((mid*(mid+1))/2 >= X){
                hi=mid;
            }
            else{
                lo=mid+1;
            }
        }
        printf("%lld\n", lo);
    }
    return 0;
}


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

using namespace std;

int main() {
	int num[100000] = { 0 };
	int length = 0,i=0,pos,move,f;
	char S[100000] = { 0 };
	cin >> S;
	while (1) {
		if (S[i]=='R'||S[i]=='L') {
			length++;
			i++;
		}
		else
			break;
	}
	//cout << length << endl;
	for (i = 0; i < length; i++) {
		pos = i;
		move = 0;
		f = 0;
		if (S[i] == 'R') {
			pos++;
			move++;
			while (1) {
				if (S[i + move] == 'R') {
					pos++;
					move++;

				}
				else {
					if (move % 2) {
						pos--;
						f++;
					}
					break;
				}
			}
		}
		if (S[i] == 'L') {
			pos--;
			move++;
			while (1) {
				if (S[i + move] == 'L') {
					move++;
				}
				else {
					if (move % 2) {
						pos++;
						f++;
					}
					break;
				}
			}
		}
		num[pos]++;
		if (move > 1) {
			if (S[i] == 'R') {
				num[pos] += (move-1) / 2;
				num[pos - 1 + 2 * f] += move / 2;
			}
			else {
				num[pos] += (move-1) / 2;
				num[pos + 1-2*f] += move / 2;
			}
			i += move - 1;
		}
	}
	for (i = 0; i < length; i++)
		cout << num[i] << " ";
	return 0;
}

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

using namespace std;

typedef long long ll;
int main()
{
    ll n, m; 
    cin >> n >> m;
    map<ll, vector<ll>> dmap;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        dmap[a].push_back(b);
    }
    ll rew = 0;
    priority_queue<ll> pq;
    for (int i = 1; i <= m; i++) {
        vector<ll> v = dmap[i];
        for (int k = 0; k < v.size(); k++) {
            pq.push(v[k]);
        }

        if (!pq.empty()) {
            rew += pq.top();
            pq.pop();
        }
    }

    cout << rew << endl;
    return 0;
}


Measured memory_bytes: 10880
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,x,y = nm()

dist = [0]*n

for i in range(1,n+1):
  for j in range(i+1,n+1):
    naive = j-i
    cand = naive
    if i<x:
      if x<=j<=y:
        cand = x-i+1+y-j
      elif j>y:
        cand = x-i+1+j-y
    elif x<=i<=y:
      if j<=y:
        cand = i-x+1+y-j
      else:
        cand = i-x+1+j-y
    d = min(naive,cand)
    dist[d]+=1

for i in range(1,n):
  print(dist[i])

Measured memory_bytes: 3444
#include<algorithm>
#include<cstdio>
using namespace std;
int A,B,sl,fh;
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	A=rd();B=rd();
	if(A>=13) printf("%d\n",B);
	else if(A>=6) printf("%d\n",B/2);
	else puts("0");
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int S = N % 10;
  
  if (S == 2 || S == 4 || S == 5 || S == 7 || S == 9) {
    cout << "hon" << endl;
  } else if (S == 0 || S == 1 || S == 6 || S == 8) {
    cout << "pon" << endl;
  } else {
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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

const int INF = INT_MAX;

vector<vector<pair<int, int> > > edge(100001);
vector<int> dist(100001, INF);
vector<bool> visited(100001, false);

int n, m;
bool bfs(int i, int d){
  if(visited[i] && d != dist[i]) return false;

  if(visited[i] && d == dist[i]) return true;

  visited[i] = true;
  dist[i] = d;
  rep(j, edge[i].size()){
    if(! bfs(edge[i][j].first, d + edge[i][j].second)) return false;
  }
  return true;
}

int main(){
  cin >> n >> m;
  rep(i, m){
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    edge[l].push_back(make_pair(r, d));
    edge[r].push_back(make_pair(l, -d));
  }
  rep(i, n){
    if(!visited[i]){
      if(!bfs(i, 0)){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

}


Measured memory_bytes: 11008
#include<algorithm>
#include<vector>
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> P;
    int PP[N];
    for(int i = 0 ; i< N;i++){
        cin >> PP[i];
        P.push_back(PP[i]);
    }
    sort(P.begin(),P.end());
    int cont = 0;
    string ans ="YES";
    for(int i = 0; i < N ;i++){
           if(P[i]!=PP[i])cont++;
            if(cont >2)ans ="NO";
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n,s[1000],temp;
    scanf("%d",&n);
    for(int i=0;i<1000;i++)s[i]=0;
    while(n--){
        scanf("%d",&temp);
        s[temp]++;
    }
    for(int i=990;i>=0;i--){
        s[i]+=s[i+1];
        if(s[i]>=i){
            printf("%d\n",i);
            break;
        }
    }
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define A_MAX 10000000000000

int main()
{
  int n;cin>>n;
  vector<ll> a(n+1);
  int i,j;
  rep(i,n+1)cin>>a[i];
  bool ok=true;
  ll left=1;
  vector<ll> marg(n+1);
  rep(i,n+1)
  {
    left-=a[i];
    if(left<0)
    {
      ok=false;
      break;
    }
    marg[i]=left;
    if(left>=A_MAX)
    {
      ok=true;
      for(j=i;j<=n;j++)
      {
        marg[j]=A_MAX;
      }
      break;
    }
    left*=2;
  }
  if(a[n]==0)ok=false;
  if(!ok)cout<<-1<<endl;
  else
  {
    ll ans=0;
    ll kuki=0;
    ll ed=a[n];
    for(i=n;i>=0;i--)
    {
      if(i!=0)
      {
        ed=kuki+a[i];
        ans+=(kuki+a[i]);
        kuki=min(marg[i-1],ed);
      }
      else ans++;
    }
    cout<<ans<<endl;
  }
  
}


Measured memory_bytes: 4764
h, w = map(int, input().split())
ls = [[_ for _ in input()] for _ in range(h)]

for i in range(h):
    ls[i] = ["."] + ls[i] + ["."]

ls_s = [["."] * len(ls[0])]
ls_s.extend(ls)
ls_s.extend([["."] * len(ls[0])])

for i in range(1, h+1):
    for j in range(1, w+1):
        if ls_s[i][j] == "#":
            if ls_s[i-1][j] == ls_s[i+1][j] == ls_s[i][j-1] == ls_s[i][j+1] == ".":
                print("No")
                break
            elif i == h and j == w:
                print("Yes")
        elif i == h and j == w:
            print("Yes")
    else:
        continue
    break

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int N, L[10],wa=0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &L[i]);
	}
	sort(L, L + N, greater<int>());
	for (int i = 1; i < N; i++) {
		wa += L[i];
	}
	if (L[0] < wa) {
		printf("Yes");
	}
	else {
		printf("No");;
	}
	return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int A=in();
	int num = 0;
	for(int i=0;i<A;i++){
		int v = i+1,q=0;
		while(v){
			v /= 10;
			q++;
		}
		if(q%2) num++;
	}

	cout << num << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>


using namespace std;

int main(void)
{
	int n,l;
	cin >> n;
	cin >> l;
	int i;
	vector<string> str(n);
	for (i = 0; i < n; i++)
	{
		cin >> str[i];
	}
	
	sort(str.begin(), str.end());
	for (i = 0; i < n; i++)
	{
		cout << str[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
namespace tst
{
    class Program
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] In = Console.ReadLine().Split(' ');
            int[] D = new int[n];
            for(int i=0; i<n; i++)
            {
                D[i] = int.Parse(In[i]);
            }
            int sum = 0;
            for(int i=0; i<n-1; i++)
            {
                for(int j=i+1; j<n; j++)
                {
                    sum += (D[i] * D[j]);
                    //Console.WriteLine("i={0},j={1},sum={2}",i,j,sum);
                }
            }
            Console.WriteLine(sum);
        }
    }
}

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

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

  int ans=0;
 long  int x,y;
  
    for(int i=0; i<n; i++) 
    {
      	cin >> x >> y;
      if(x*x + y*y <= d*d)
      {ans ++;}
    }
  	cout << ans << endl;
}

Measured memory_bytes: 3632
def main():
    n = int(raw_input().strip())
    data = map(int, raw_input().split())
    change = bubble_sort(n, data)
    print " ".join([str(x) for x in data])
    print change

def bubble_sort(n, data):
    change = 0
    for i in xrange(n):
        for j in xrange(n - 1, i, -1):
            if data[j] < data[j - 1]:
                change += 1
                data[j], data[j - 1] = data[j - 1], data[j]
    return change

if __name__ == '__main__':
    main()


Measured memory_bytes: 4664
from heapq import heappush, heappop

def dijkstra(edges, size, source):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    distance = [float('inf')] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance[n-1]

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

for i in range(m):
    b[a[i][0]-1].append((a[i][1]-1,a[i][2]))

# 戻るルートをコストゼロで追加
for i in range(n-1):
    b[i+1].append((i,0))

x=dijkstra(b,n,0)

if x==float('inf'):
    print(-1)

else:
    print(x)

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

using namespace std;

int main() {
	while (1) {
		int N; cin >> N; if (N == 0) break;
		
		vector< pair<double, string> > items;
		for (int i = 0; i < N; i++) {
			string name; cin >> name;
			int p, a, b, c, d, e, f, s, m;
			cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			
			int time = a + b + c;
			for (int j = 0; j < m; j++) time += (d + e);
			int num = f * m;
			int prof = s * num;
			
			items.push_back(make_pair((-1.0) * (double)(prof - p) / (double)time, name));
		}
		
		sort(items.begin(), items.end());
		
		for (int i = 0; i < N; i++) {
			cout << items[i].second << endl;
		}
		cout << "#" << endl;
	}
	
	return 0;
}

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

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    sort(h.begin(), h.end());

    int ans = h[K - 1] - h[0];
    for (int i = K; i < N; i++) {
        chmin(ans, h[i] - h[i - K + 1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
vector<int> w[maxn];
long long d[maxn];
int a[maxn], b[maxn], c[maxn];
void work(int x, int p) {
	for (int i = 0; i < w[x].size(); i++) {
		int u = w[x][i];
		if (a[u] == p || b[u] == p) continue;
		if (a[u] == x) {
			d[b[u]] = d[x] + c[u];
			work(b[u], x);
		} else {
			d[a[u]] = d[x] + c[u];
			work(a[u], x);
		}
	}
} 
int main()
{
	int n, q, k, x, y;
	
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		w[a[i]].push_back(i);
		w[b[i]].push_back(i);
	}
	scanf("%d%d", &q, &k);
	d[k] = 0;
	work(k, 0);
	while (q--) {
		scanf("%d%d", &x, &y);
		printf("%lld\n", d[x] + d[y]);
	}
} 

Measured memory_bytes: 15488
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// ***************************************

vector<ll> memo(1e5, -1);
set<ll> root;
vector<vector<ll>> graph;

ll rec(ll parent){
	if (memo[parent] != -1) return memo[parent];
	if (graph[parent].empty()) return 0;

	ll ret = 0;
	for (auto& c : graph[parent]) {
		chmax(ret, rec(c));
	}
	ret++;
	return memo[parent] = ret;
}

int main(void) {

	ll N, M;
	cin >> N >> M;
	graph.assign(N, vector<ll>());

	ll x, y;
	set<ll> not_root;
	REP(i, M) {
		cin >> x >> y;
		x--; y--;
		graph[x].push_back(y);
		not_root.insert(y);
	}

	REP(i, N) {
		if(not_root.find(i) == not_root.end())
			root.insert(i);
	}

	ll ans = 0;
	for (auto& x : root) {
		chmax<ll>(ans, rec(x));
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
      string N;
      cin >> N;
      if (N.at(2) == N.at(3) && N.at(4) == N.at(5)){
        cout << "Yes" << endl;
      }
	  else {
        cout << "No" << endl;
      }}  

Measured memory_bytes: 256
import numpy as np
import sys
from operator import itemgetter
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = []
for i in range(N):
    a,b = IL()
    l.append([a,b,a+b])

l.sort(key=itemgetter(2),reverse=True)

chokudai = 0
aoki = 0
for i in range(N):
    if i%2 == 0:
        chokudai += l[i][0]
    else:
        aoki += l[i][1]

print(chokudai-aoki)

Measured memory_bytes: 33884
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	x := []rune(s)
	y := []rune(t)

	sort.Slice(x, func(i, j int) bool {
		return x[i] < x[j]
	})
	sort.Slice(y, func(i, j int) bool {
		return y[i] > y[j]
	})

	for i := 0; i < int(math.Min(float64(len(x)), float64(len(y)))); i++ {
		if x[i] < y[i] {
			fmt.Println("Yes")
			return
		} else if x[i] > y[i] {
			fmt.Println("No")
			return
		}
	}

	if len(x) < len(y) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    int zenbu = 0;
    for (int i = 0; i < n; i++)
    {
        a[i] = l + i;
        zenbu += a[i];
    }
    int ans = INT_MAX;
    int res;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        tmp = abs(zenbu - (zenbu - a[i]));
        ans = min(ans, tmp);
        if (tmp == ans)
            res = zenbu - a[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.C
{
    public class Program
    {
        public static long N { get; private set; }
        public static long[] C { get; private set; }
        public static long[] S { get; private set; }
        public static long[] F { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            N = ReadLong();
            C = new long[N - 1];
            S = new long[N - 1];
            F = new long[N - 1];
            for (int i = 0; i < N - 1; i++)
            {
                (C[i], S[i], F[i]) = Read3Longs();
            }

            var sb = new StringBuilder();
            for (int i = 0; i < N; i++)
            {
                var time = ClacTime(i);
                sb.AppendLine(time.ToString());
            }

            return sb.ToString().Trim();
        }

        private static long ClacTime(int start)
        {
            // 終点の場合
            if (start == N - 1) return 0;

            // 開通まで待機
            var time = S[start];
            for (int i = start; i < N - 1; i++)
            {
                // 移動時間
                time += C[i];

                // 次の駅到着後、電車が来るまで待機
                if (i < N - 2)
                {
                    // まだ始発が出ていない場合
                    if (time < S[i + 1])
                    {
                        time += S[i + 1] - time;
                    }
                    else
                    {
                        time += time % F[i + 1] == 0 ? 0
                            : ((time / F[i + 1]) + 1) * F[i + 1] - time;
                    }
                }
            }

            return time;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = (int)1e5+100;
int n, m, h[maxn];
vvi G(maxn);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> n >> m;
    for1(i, n) cin >> h[i];
    forn(i, m) {
        int u, v;
        cin >> u >> v;
        G[u].eb(v);
        G[v].eb(u);
    }
    int ans = 0;
    for1(i, n) {
        bool flag = true;
        for (int j : G[i]) {
            if (h[i] <= h[j]) {
                flag = false;
                break;
            }
        }
        if (flag) ++ans;
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 8680
#include<iostream>

using namespace std;

// x > y ??§??????x, y???GCD????±???????
int gcd(long int x, long int y)
{
  if(y == 0)
    return x;
  else
    return gcd(y, x % y);
}

int main(){
  long int x, y;
  cin >> x >> y;
  if(y > x)
    swap(x, y);
  cout << gcd(x, y) << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(y%2!=0)
        cout<<"No"<<endl;
    else 
    {
        int crane = 0;
        int turtle = x;
        int flag=0;
        while(crane <= x)
        {
            if(crane*2 + turtle*4 == y)
            {
                flag=1;
                break;
            }
            crane++;
            turtle--;
        }
        if(flag==0)
            cout<<"No"<<endl;
        else 
            cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
n,m = LI()
print((n-1)*(m-1))
"""

#B
s = S()
print(s[0]+str(len(s)-2)+s[-1])
#C
"""
n = I()
a = LI()
d = [0,0]
for i in a:
    if i%2:
        d[0] += 1
    if i%4 == 0:
        d[1] += 1
if n % 2:
    d[0] -= 1
d[0] -= d[1]
if d[0] <= 0:
    print("Yes")
else:
    print("No")
"""

#D
"""
h,w = LI()
n = I()
a = LI()
c = [[None for x in range(w)] for y in range(h)]
i = 0
for y in range(h):
    if y%2:
        for x in range(w)[::-1]:
            if not a[i]:
                i += 1
            c[y][x] = i+1
            a[i] -= 1
    else:
        for x in range(w):
            if not a[i]:
                i += 1
            c[y][x] = i+1
            a[i] -= 1
for i in c:
    print(*i)
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    map<int,int>m;int cc=0;
    for(int i=0;i<n;i++){
        if(a[i]<=399&&m[1]==0)
            m[1]=1;
        else if(a[i]<=799&&a[i]>=400&&m[2]==0)
            m[2]=1;
        else if(a[i]<=1199&&a[i]>=800&&m[3]==0)
        m[3]=1;
        else if(a[i]<=1599&&a[i]>=1200&&m[4]==0)
        m[4]=1;
        else if(a[i]<=1999&&a[i]>=1600&&m[5]==0)
        m[5]=1;
        else if(a[i]<=2399&&a[i]>=2000&&m[6]==0)
        m[6]=1;
        else if(a[i]<=2799&&a[i]>=2400&&m[7]==0)
        m[7]=1;
        else if(a[i]<=3199&&a[i]>=2800&&m[8]==0)
        m[8]=1;
        else if(a[i]>=3200)
            cc++;
    }
    if(cc==n){
        cout<<1<<" "<<cc<<endl;
        return 0;
    }
    int cnt=0;
    for(int i=1;i<=8;i++)
        if(m[i]>0)cnt++;
    cout<<cnt<<" "<<cnt+cc<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
N = int(input())

A = [0] * N
B = [0] * N
lst = [0] * N
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
    lst[i] = A[i] % B[i] #何回オーバーしているか

# print (lst)

ans = 0
for i in range(N - 1, -1, -1):
    lst[i] = (lst[i] + ans) % B[i]
    ans += (B[i] - lst[i] % B[i]) % B[i]
    # print (ans)
    # ans += (B[i] - (lst[i][0] + ans) % B[i]) % B[i]
    
print (ans)


Measured memory_bytes: 14836
n,k=map(int,input().split())
d=[]
A=[]
for i in range(k):
  d.append(int(input()))
  A.append(list(map(int,input().split())))

a=[]
for i in range(len(A)):
  for j in range(len(A[i])):
    if not(A[i][j] in a):
      a.append(A[i][j])
#     print("A[i][j]=",A[i][j])
# print(a)

print(n-len(a))

Measured memory_bytes: 67848
//code by lynmisakura.wish to be accepted
/****************************/
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;

#define itn int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define MAX_N 200020
int par[MAX_N];
int main(void){
	
	int n;cin >> n; int qe;cin >> qe;
	vector<vector<int>> T(n,vector<int>(0));
	rep(i,n-1){
		int a,b;cin >> a >> b;
		a--,b--;
		T[a].pb(b);T[b].pb(a);
	}
	vector<int> parent(n,-1);
	vector<ll> p(n,0LL);
	rep(i,qe){
		ll a,x;cin >> a >>x;
		a--;
		p[a] += x;
	}
	
	
	vector<ll> ans(n,0LL);
	
	
	queue<int> q;
	q.push(0);
	vector<int> check(n,0);
	check[0] = 1;
	q.push(0);
	parent[0] = 0;
	ans[0] = p[0];
	while(!q.empty()){
		int x = q.front(); q.pop();
		check[x] = 1;
		for(int i = 0;i < T[x].size();i++){
			if(check[T[x][i]] == 0){
				q.push(T[x][i]);
				ans[T[x][i]] = ans[x] + p[T[x][i]];
			}
		}
	}
	//rep(i,n) debug(p[i]);
	rep(i,n) cout << ans[i] << endl;
	return 0;
}

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

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;

const int N = 1e4 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int f[N];

int main() {
	ios::sync_with_stdio(0);

	int n;
	cin >> n;
	for (int i = 1; i <= 100; i++)
		for (int j = 1; j <= 100; j++)
			for (int k = 1; k <= 100; k++) {
				int x = i * i + j * j + k * k + i * j + i * k + j * k;
				if (x < N) f[x]++;
			}

	for (int i = 1; i <= n; i++)
		cout << f[i] << endl;

	return 0;
}


Measured memory_bytes: 3644
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n = int(input())
for a in range(1, 10):
  for b in range(1, 10):
    if(a * b == n):
      print('Yes')
      exit(0)
print('No')


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

int main() {
	ll n; cin >> n;
	string s; cin >> s;
	ll cnt = 0;
	string ans = "";

	rep(i, 0, s.size()) {
		if (s[i] == '(') {
			cnt++;
			ans += s[i];
		}
		else {
			cnt--;
			ans += s[i];
		}

		if (cnt < 0) {
			ans = '(' + ans;
			cnt++;
		}
	}

	rep(i, 0, cnt) {
		ans = ans + ')';
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
right,acute,obtuse = 0,0,0

while True:
    triangle = sorted([int(i) for i in input().split()])

    # 三角形の成立条件
    if triangle[2] < triangle[0] + triangle[1]:
        longest_2 = triangle[2] ** 2
        side1_2 = triangle[0] ** 2
        side2_2 = triangle[1] ** 2
        # 直角三角形の成立条件
        if longest_2 == side1_2 + side2_2:
            right += 1
        # 鋭角三角形の成立条件
        elif longest_2 < side1_2 + side2_2:
            acute += 1
        # どちらでもないなら鈍角三角形
        else:
            obtuse += 1
    # 三角形ではないときは終了する
    else:
        break

print('%d %d %d %d' % (right+acute+obtuse,right,acute,obtuse))


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

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int price=0;

    int rest;


    if(A+B<2*C){
        cout << A*X+B*Y << endl;
    }

   
    else{
        if(X>Y){
            price=price+2*C*Y;
            rest=X-Y;
            cout << min(A,2*C)*rest+price << endl;
        }
        else{
            price=price+2*C*X;
            rest=Y-X;
            if(B>2*C){
                cout << price+2*C*rest << endl;
            }
            else{
                cout << price+B*rest << endl;
            }
        }
    }
}


Measured memory_bytes: 256
q=gets.to_i
q.times{
  a,b=gets.split.map(&:to_i)
  s=a*b
  c=Math.sqrt(s).to_i
  c-=1 if c**2==s
  if a==b
    p 2*a-2
  else
    p c*(c+1)>=s ? 2*c-2:2*c-1
  end
}


Measured memory_bytes: 1788
N = int(input())
E = []
for i in range(N):
    s, t = map(str, input().split())
    E.append((s, int(t), i+1))
#At first, sorted by the score
E.sort(key = lambda x: x[1], reverse = True)
#sorted by the alphabet
E.sort(key = lambda x: x[0])

for k in range(N):
    print(E[k][2])

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
import bisect

N = int(input())
A = [-int(input()) for _ in range(N)]

Color = []
for a in A:
  idx = bisect.bisect_right(Color,a)
  if idx == len(Color):
    Color.append(a)
  else:
    Color[idx] = a
  #Color.sort()
  #print(Color)
print(len(Color))

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

string s;
int main(void){
    cin >> s;
    int start = stoi(s.substr(0,2));
    int end = stoi(s.substr(2));

    if ((start <= 0 and end > 12) or (start > 12 and end <= 0)){
        cout << "NA" << endl;
        return 0;
    }
    if(start >= 1 and start <= 12 and end >= 1 and end <= 12) cout << "AMBIGUOUS" << endl;
    else if (1 <= start and start <= 12) cout << "MMYY" << endl;
    else if (1 <= end and end <= 12) cout << "YYMM" << endl;
    else cout << "NA" << endl;

    return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout << '\n';
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n';

void solve(){
  string s; cin>>s;
  if(s=="ABC"){
    cout<<"ARC";LOL
  }
  else{
    cout<<"ABC";LOL
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int _ = 1; //cin >> _;
  for(int i = 1 ; i <= _ ; i++){
    //cout << "Case #" << i << ": ";
    solve();
  }
  return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int l,m=0,n,s=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>l;
		m=max(m,l);
		s+=l;
	}
	if(s-m>m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll arr[5],m=1e18,n,ans=0;
  cin>>n;
  for(int i=0;i<5;i++) cin>>arr[i],m=min(m,arr[i]);
  if(n<=m) ans=5;
  else
  {
    ll temp=0;
    temp=n/m;
    if(n%m==0) temp--;
    ans=5+temp;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256