akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using V = vector<int>;
using VV = vector<V>;
using P = pair<int, int>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


template<typename T>
struct RMQ {
  vector<T> v;
  VV st; // sparse table
  int op(int a, int b) { return v[a]==v[b] ? min(a, b) : (v[a]<v[b] ? a : b); } 
  void init(const vector<T> &_v) {
    v = _v;
    int n = v.size();
    st = {V(n)}; iota(all(st[0]), 0);
    for (int j=1; 1<<j <= n; ++j) {
      int m = n-(1<<j)+1;
      st.push_back(V(m));
      rep(i, m) st[j][i] = op(st[j-1][i], st[j-1][i+(1<<(j-1))]);
    }
  }
  int index(int l, int r) { int d = 31-__builtin_clz(r-l); return op(st[d][l], st[d][r-(1<<d)]); }
  T query(int l, int r) { return v[index(l, r)]; }
};


V c, dst;
V dall(1);
V tl, tour, dep;
vector<vector<P>> G;
RMQ<int> R;
int tt = 0;

VV cd, ct;

void dfs(int &t, int u, int p=-1, int d=0) {
  tour[t] = u;
  dep[t] = d;
  tl[u] = t++;
  for (auto &[i, v] : G[u]) if (v != p) {
    cd[c[i]].push_back(dst[i]);
    dall.push_back(dst[i]);
    ct[c[i]].push_back(tt++);
    dfs(t, v, u, d+1);
    cd[c[i]].push_back(-dst[i]);
    dall.push_back(-dst[i]);
    ct[c[i]].push_back(tt++);
  }
  tour[t] = p;
  dep[t] = d-1;
  ++t;
}

int lca(int u, int v) {
  return tour[R.index(min(tl[u], tl[v]), max(tl[u], tl[v]))];
}


int main() {
  int n, q; cin >> n >> q;
  c.assign(n, 0);
  dst.assign(n, 0);
  tl.assign(n, 0);
  tour.assign(2*n, 0);
  dep.assign(2*n, 0);
  G.assign(n, vector<P>());
  cd.assign(n, V(1));
  ct.assign(n, V());

  rep(i, n-1) {
    int a, b;
    cin >> a >> b >> c[i] >> dst[i];
    --a, --b;
    G[a].emplace_back(i, b);
    G[b].emplace_back(i, a);
  }

  int t = 0;
  dfs(t, 0);
  R.init(dep);

  auto cE = cd;
  for (auto &v : cE) for (auto &e : v) e = clamp(e, -1, 1);
  for (auto &v : cd) rep(i, v.size()-1) v[i+1] += v[i];
  for (auto &v : cE) rep(i, v.size()-1) v[i+1] += v[i];
  rep(i, dall.size()-1) dall[i+1] += dall[i];

  auto f = [&] (int x, int y, int u, int v) {
    int &i = tl[u];
    int &j = tl[v];
    int ix = lower_bound(all(ct[x]), i) - ct[x].begin();
    int jx = lower_bound(all(ct[x]), j) - ct[x].begin();

    int res = dall[j] - dall[i];
    res -= cd[x][jx] - cd[x][ix];
    res += (cE[x][jx] - cE[x][ix]) * y;
    return res;
  };

  rep(_, q) {
    int x, y, u, v; cin >> x >> y >> u >> v;
    --u, --v;
    int w = lca(u, v);
    int ans = f(x, y, w, u) + f(x, y, w, v);
    cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 48368
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
D = list(map(int, sys.stdin.buffer.readline().split()))

D.sort()


def dist(h, counts):
    i = 0
    while counts[(h - i) % 24] == counts[(h + i) % 24] == 0:
        i += 1
    return i


counts = [0] * 25
counts[0] = 1
counts[24] = 1
for i in range(N):
    if dist(D[i], counts) > dist(24 - D[i], counts):
        counts[D[i]] += 1
    else:
        counts[24 - D[i]] += 1

if max(counts) >= 2:
    print(0)
    exit()

cc = []
for i in range(len(counts)):
    if counts[i]:
        cc.append(i)

ans = 24
for a, b in zip(cc, cc[1:]):
    ans = min(ans, abs(a - b))
print(ans)


Measured memory_bytes: 13796
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    long long int N, tmp, sum=0, left=0, dif = 2020202021;
    vector<int> A;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> tmp;
        A.push_back(tmp);
        sum += tmp;
    }


    for (int i = 0; i < N; i++) {
        left += A[i];
        tmp = abs(sum - 2 * left);
        if (dif > tmp) {
            dif = tmp;
        }
    }

    cout << dif;

    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
long long ans;
string s;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        long long x=s[i]-'0';
        for(int j=s.size()-i-1;j;j--){
            ans+=x*(1LL<<(i+j-1));
            x*=10;
        }
        ans+=x*(1LL<<i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int a,b;
	int ans;
	cin>>a>>b;
	if(12.5*a+12.5>10*b&&10*b+10>12.5*a)
	{
		cout<<max((25*a+1)/2,10*b);
	}
	else
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
void swap(int *, int *);
 
int main(){
 
  int i, j, n, *A, minj, count=0;
 
  scanf("%d",&n);
 
  A = (int *)malloc(sizeof(int) * n);
 
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
 
  for(i=0; i<n-1; i++){
    minj = i;
    for(j=i; j<n; j++){
      if(A[j] < A[minj]){
    minj = j;
      }
    }
    swap(&A[i], &A[minj]);
    if(A[i] != A[minj]){
      count++;
    }
  }
 
  for(i=0; i<n-1; i++){
    printf("%d ", A[i]);
  }
 
  printf("%d\n",A[i]);
  printf("%d\n",count); 
 
  return 0;
}
 
void swap(int *a, int *b){
  int c;
 
  c = *a;
  *a = *b;
  *b = c;
 
}

Measured memory_bytes: 1800
#include <stdio.h>
int main(void){
    // Your code here!
    int x,i;
    i=1;
    
    while(scanf("%d",&x) !=EOF)
    {
        if(x == 0)break;
    printf("Case %d: %d\n",i,x);
    i++;
    }
    return 0;
}



Measured memory_bytes: 2048
using System;
class A_EatingSymbolsEasy
{
    static void Main(string[] args)
    {
		int sum = 0;
        // スペース区切りの整数の入力
		string input = Console.ReadLine();
		for (int i = 0; i < input.Length;i++){
			switch(input[i]){
				case '+':
					sum++;
					break;
				case '-':
					sum--;
					break;
			}
		}

        //出力
		Console.WriteLine(sum);
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top =0;
  char s[100];

  while( scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }
    else if (s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }
    else if (s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }
    else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}



Measured memory_bytes: 2076
#include <iostream>
using namespace std;
typedef long long ll;
ll n, W, v[110], w[110], dp[110][10010];
int main(void){
    // Your code here!
    cin >> n >> W;
    for (ll i = 0; i < n; i++) cin >> v[i] >> w[i];
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j <= W; j++) {
            if (j < w[i]) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
        }
    }
    cout << dp[n][W] << endl;
}



Measured memory_bytes: 10924
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく
int N;
vector<int> E[200001];
vector<bool> seen;
typedef pair<int, int> P;
int D[101];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

int mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    if (M & 1) res = (res * N) % MOD;
    return res;
}

int main() {
    long long N,M;
    cin >> N >> M;


    cout << mod_pow(N,M) << endl;
}



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

int main(){
    int x, y;
    cin >> x >> y;

    long long int ans = 0;
    if(x == y) ans = 0;
    else if(x == 0){
        ans = abs(y);
        if(y < 0) ans += 1;
    }
    else if(y == 0){
        ans = abs(x);
        if(x > 0) ans += 1;
    }
    // different sign
    else if(x == -y) ans = 1;
    else if(x > 0 && y < 0) ans = 1 + abs(x-(-y));
    else if(x < 0 && y > 0) ans = min(y-x, 1+abs(y-(-x)));
    // same sign
    else if(x > y) ans = 2 + (x-y);
    else if(x < y) ans = y-x;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

void swap(int* a, int* b){
  int l = *a;
  *a = *b;
  *b = l;
}

int main(){
  int w, n, a, b, bows[31], i;
  for(i = 0;i <= 31;i++)
    bows[i] = i;
  scanf("%d", &w);
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d,%d", &a, &b);
    swap(bows + a, bows + b);
  }
  for(i = 1;i <= w;i++){
    printf("%d\n", bows[i]);
  }
  return 0;
}

Measured memory_bytes: 596
# ABC169c


def main():
    import sys
    import math
    from decimal import Decimal
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    a, b = map(Decimal, input().split())
    print(math.floor(a*b))


if __name__ == '__main__':
    main()


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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d = a / b;
    int r = a % b;
    double f = double (a) / double (b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << setprecision(5) << f;
    cout << endl;
    
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL x,y,z,ans;
    vector<pair<LL,LL>> bc;
    vector<LL> diff;
    Problem(LL x,LL y, LL z):x(x),y(y),z(z),ans(0),diff(y+1){};

    void solve(){
        for(int i=0; i<x+y+z; ++i){
            LL a,bb,cc;
            cin >> a >> bb >> cc;
            ans+=a;
            bc.emplace_back(bb-a,cc-a);
        }
        sort(bc.begin(),bc.end(),[&](pair<LL,LL> &a, pair<LL,LL>&b){return a.second>b.second or(a.second==b.second and a.first<b.first);});

        priority_queue<LL> diffs;
        for(int i=0; i<z; ++i){
            ans+=bc[i].second;
            diffs.push(bc[i].first-bc[i].second);
        }
        for(int i=1; i<=y; ++i){
            diff[i]=diff[i-1]+diffs.top();
            diffs.pop();
            diffs.push(bc[z-1+i].first-bc[z-1+i].second);
        }
        DBG(bc,diff)

        priority_queue<LL>bs;
        for(int i=y+z-1; i<x+y+z; ++i){
            bs.push(bc[i].first);
        }
        LL tmp = diff[y];
        for(int i=z; i<y+z; ++i){
            tmp+=bc[i].second;
        }
        LL maxi =tmp;
        DBG(ans,maxi,bs.size())
        for(int i=y-1; i>=0; --i){
            tmp-=bc[z+i].second;
            tmp+=diff[i]-diff[i+1];
            tmp+=bs.top();
            DBG(i,tmp,bs.top())
            bs.pop();
            maxi=max(maxi,tmp);
            bs.push(bc[z+i-1].first);
        }
        cout << ans+maxi <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long x,y,z;
    cin >> x >> y >> z;

    Problem p(x,y,z);
    p.solve();
    return 0;
}



Measured memory_bytes: 3696
def resolve():
    N = int(input())
    S = sorted(list(sorted(input()) for _ in range(N)))
    count = 0
    S_dict = {}
    for i in range(N):
        s = str(S[i])
        if s in S_dict:
            tmp =  S_dict[s]
            S_dict[s] = tmp + 1
            count = count + tmp
        else:
            S_dict.setdefault(s,1)
    print(count)

    
resolve()

Measured memory_bytes: 44592
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
using int64 = long long;

vector< int64 > divisor(int64 n)
{
    vector< int64 > ret;
    for(int64 i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return(ret);
}
int main(){
    int n,k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
}
int main2(){
    int n;
    cin >> n;
    vector<string>s(n);
    rep(i,n)cin >> s[i];
    int ans = 0;
    rep(i,n){
        int k = (int) s[i].size();
        rep(j,k-1){
            if(s[i][j] == 'A' and s[i][j+1] == 'B')ans++;
        }
    }
    int a = 0, b = 0, c = 0, d = 0;
    rep(i,n){
        if(s[i][0] == 'A'){
            if(s[i].back() == 'A')a++;
            else b++;
        }else if(s[i][0] == 'B'){
            if(s[i].back() == 'A')c++;
            else d++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
//フロッピーキューブ

#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int N, ans;

struct fc {
	int c[30];
	int cost;
	bool check() {
		for (int i = 0; i < 8; i++) {
			if (c[i] != c[i + 1]) return false;
		}
		for (int i = 21; i < 29; i++) {
			if (c[i] != c[i + 1]) return false;
		}
		for (int i = 9; i < 10; i++) {
			if (c[i] != c[i + 1]) return false;
		}
		for (int i = 12; i < 13; i++) {
			if (c[i] != c[i + 1]) return false;
		}
		for (int i = 15; i < 16; i++) {
			if (c[i] != c[i + 1]) return false;
		}
		for (int i = 18; i < 20; i++) {
			if (c[i] != c[i + 1]) return false;
		}
		return true;
	}
	void s(int n) {
		if (n == 1) {
			swap(c[0], c[23]);
			swap(c[3], c[26]);
			swap(c[6], c[29]);
			swap(c[20], c[9]);
			swap(c[15], c[17]);
		}
		if (n == 2) {
			swap(c[2], c[21]);
			swap(c[5], c[24]);
			swap(c[8], c[27]);
			swap(c[18], c[11]);
			swap(c[14], c[12]);
		}
		if (n == 3) {
			swap(c[0], c[27]);
			swap(c[1], c[28]);
			swap(c[2], c[29]);
			swap(c[15], c[14]);
			swap(c[20], c[18]);
		}
		if (n == 4) {
			swap(c[6], c[21]);
			swap(c[7], c[22]);
			swap(c[8], c[23]);
			swap(c[17], c[12]);
			swap(c[9], c[11]);
		}
		return;
	}

};

void bfs(fc p) {
	queue<fc> Q;
	Q.push(p);
	while (!Q.empty()) {
		fc t = Q.front(); Q.pop();
		if (t.check()) 
			ans = min(ans, t.cost);
		if (t.cost >= ans) continue;
		for (int i = 0; i < 4; i++) {
			fc _t = t;
			_t.cost++;
			_t.s(i + 1);
			Q.push(_t);
		}
	}
	return;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		fc p;  ans = 8;
		for (int j = 0; j < 30; j++) {
			cin >> p.c[j]; 
		}
		p.cost = 0;
		bfs(p);
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 11320
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

vector<vector<int>> G;

int solve(int now) {
  if (len(G[now]) == 0)
    return 0;

  vector<int> childs;
  for (auto next : G[now]) {
    childs.pb(solve(next));
  }

  sort(all(childs), greater<int>());
  int mx = 0;
  rep(i, len(childs)) {
    childs[i] += i;
    chmax(mx, childs[i]);
  }

  return mx + 1;
}

signed main() {
  int N;
  cin >> N;
  vector<int> a(N - 1);
  rep(i, N - 1) {
    cin >> a[i];
    a[i]--;
  }


  G = vector<vector<int>>(N);
  rep(i, N - 1) {
    G[a[i]].pb(i + 1);
  }

  cout << solve(0) << endl;
}

Measured memory_bytes: 13952
import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n=int(input())
edges=[[] for i in range(n)]
for i in range(n-1):
    a,s,w=map(int,input().split())
    edges[a-1].append([s-1,w]);edges[s-1].append([a-1,w])
colors=[-1]*n
colors[0]=1
def dfs(now):
    for to,cost in edges[now]:
        if colors[to]==-1:
            colors[to]=(cost+colors[now])%2
            dfs(to)

dfs(0)
print(*colors,sep="\n")


Measured memory_bytes: 85168
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define PB push_back
#define MOD 10000007
#define PI 3.14159265359

using namespace std;

int main(){

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    int ans = 0;
    int ans1 = 0;


    while(a > 0){
        a = a - d;
        ans++;
    } 
    while(c > 0){
        c = c - b;
        ans1++;
    } 

    if(ans >= ans1){
        puts("Yes");
    }else{
        puts("No");
    }
}
    


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	string A, B, C;
	cin >>A >>B >>C;
	if ((A.back()==B.front())&&(B.back()==C.front()))
		cout <<"YES" <<endl;
	else
		cout <<"NO" <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int N;
double dp[310][310][310];

double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res += N;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main() {
    cin >> N;
    int one = 0, two = 0, three = 0;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        if (a == 1) one++;
        else if (a == 2) two++;
        else three++;
    }
    memset(dp, -1, sizeof(dp));
    cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

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


int main(){
    long long a,b,c,d,C,D;
    long long divc,divd,divcd;
    long long ans;
    long long lcmcd,tmp;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    C = c;
    D = d;
    long long x=c*d;
    if(c<d){
        tmp = c;
        c = d;
        d = tmp;
    }
 
  long long r = c % d;
  while(r!=0){
    c = d;
    d = r;
    r = c % d;
  }
    lcmcd = x/d;
    divc = b/C - (a-1)/C;
    divd = b/D - (a-1)/D;
    divcd = b/(lcmcd) - (a-1)/(lcmcd);
    ans = b - a + 1 - divc - divd + divcd;
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Array.ST
import Data.Array (elems)
import Data.Maybe (fromJust)

solve :: Int -> [[Int]] -> [Int]
solve n a = elems $ runSTArray $ do
    arr <- newArray (1, n) 0
    forM_ a $ \i -> do
        let (a:b:_) = i
        va <- readArray arr a
        writeArray arr a (va + 1)
        vb <- readArray arr b
        writeArray arr b (vb + 1)
    return arr


main :: IO ()
main = do
    [n, m] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    arr <- replicateM m (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)
    let ans = solve n arr
    forM_ ans print



Measured memory_bytes: 508
<?php
	fscanf(STDIN,"%d %d",$a,$b);
    $ans = 0;
    if($a != 1){
    	for($i=$a-1;$i>0;$i--){
        	$ans += $i;
        }
    }


    if($b != 1){
    	for($i=$b-1;$i>0;$i--){
        	$ans += $i;
        }
    }

echo $ans;

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    int n, k;
    int ans = 0;
    cin >> n >> k;

    ans = n - k + 1;

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
N, M, R = gets.split.map(&:to_i)
r = gets.split.map(&:to_i).map { |x| x - 1 }

# ワーシャルフロイド
MAX = 1<<30
dist = Array.new(N){Array.new(N, MAX)}
M.times do
  a, b, c = gets.split.map(&:to_i)
  dist[a-1][b-1] = dist[b-1][a-1] = c
end

N.times do |k|
  N.times do |i|
    N.times do |j|
      v = dist[i][k]+dist[k][j]
      dist[i][j] = v if dist[i][j] > v
    end
  end
end

ans = r.permutation.map do |perm|
  perm.each_cons(2).inject(0){|sum, (x,y)| sum+dist[x][y]}
end.min
puts ans

Measured memory_bytes: 2936
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main(){
    ll n,W;
    cin >> n >> W;
    vector<ll> v(n),w(n);
    vector<vector<ll>> x(4);
    ll c=-1;
    rep(i,n){
        cin >> w[i] >> v[i];
        if(i==0) c=w[i];
        w[i]-=c;
        x[w[i]].push_back(v[i]);
    }
    ll ans=-1;
    vector<vector<ll>> y(4);
    rep(i,4){
        sort(x[i].rbegin(),x[i].rend());
        y[i].push_back(0LL);
        rep(j,x[i].size()){
            y[i].push_back(y[i][j]+x[i][j]);
            //cout << y[i][j+1] << endl;
        }
    }
    rep(i,y[0].size()){
        rep(j,y[1].size()){
            rep(k,y[2].size()){
                rep(l,y[3].size()){
                    //cout << i << " " << j << " " << k << " " << l << endl;
                    if(j+2*k+3*l+(i+j+k+l)*c<=W){
                        ans=max(ans,y[0][i]+y[1][j]+y[2][k]+y[3][l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;
class Main{
    public static void main(String[] av){
	Scanner sc=new Scanner(System.in);
	while(true){
	int H=sc.nextInt();
	int W=sc.nextInt();
	if(H==0&&W==0) break;
	for(int i=0;i<H;i++){
	    for(int j=0;j<W;j++){
		if(i==0||i==(H-1)||j==0||j==(W-1)){
		System.out.print("#");
		}else{
		    System.out.print(".");
		}
		
	    }
	    System.out.println();
	}
	 System.out.println();
	}
    
    }
}



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

typedef pair<int,int> ii;

const int MAXN = 200005;

int N, K, L, u, v, visited[2][MAXN], cnt[2] = {1, 2};
vector<int> adjList[2][MAXN];

map<ii,int> m;

void dfs(int id, int node) {
    if (visited[id][node]) {
        return;
    } else {
        visited[id][node] = cnt[id];

        for (int i = 0; i < adjList[id][node].size(); i++) {
            int neighbor = adjList[id][node][i];

            dfs(id, neighbor);
        }
    }
}

int main() {

    scanf("%d%d%d", &N, &K, &L);
    for (int i = 0; i < K; i++) {
        scanf("%d%d", &u, &v);

        adjList[0][u].push_back(v);
        adjList[0][v].push_back(u);
    }

    for (int i = 0; i < L; i++) {
        scanf("%d%d", &u, &v);

        adjList[1][u].push_back(v);
        adjList[1][v].push_back(u);
    }

    for (int i = 1; i <= N; i++) {
        if (!visited[0][i]) {
            dfs(0, i); cnt[0] += 2;
        }
        if (!visited[1][i]) {
            dfs(1, i); cnt[1] += 2;
        }
    }

    for (int i = 1; i <= N; i++) {
        m[ii(visited[0][i], visited[1][i])]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << m[ii(visited[0][i], visited[1][i])] << " ";
    }

    return 0;
}

Measured memory_bytes: 27904
/*
[agc027] C - ABland Yard
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 200000;

int N, M;
int s[MAX_N];
set<int> g[MAX_N];
int cnt[MAX_N][2];
bool removed[MAX_N];

bool solve() {
    queue<int> q;
    for (int u = 0; u < N; u++) {
        for (int v : g[u]) {
            cnt[u][s[v]]++;
        }
        if (cnt[u][0] == 0 || cnt[u][1] == 0) {
            q.push(u);
        }
    }

    int remain = N;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (removed[u]) {
            continue;
        }
        removed[u] = true;
        remain--;

        for (int v : g[u]) {
            if (u == v) {
                continue;
            }
            g[v].erase(u);
            cnt[v][s[u]]--;
            if (cnt[v][0] == 0 || cnt[v][1] == 0) {
                q.push(v);
            }
        }
    }

    return remain > 0;
}

int main() {
    string s_str;
    cin >> N >> M;
    cin >> s_str;
    for (int i = 0; i < N; i++) {
        s[i] = (s_str[i] == 'A') ? 0 : 1;
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].insert(b);
        g[b].insert(a);
    }

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


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

int main()
{
    /*
    #ifndef ONLINE_JUDGE 
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif
    */
    
    int tt;
    cin >> tt;
    set<string>s;
    while(tt--)
    {
         string str;
         cin>>str;
         s.insert(str);
    }
    cout<<s.size();
    return 0;
}

Measured memory_bytes: 19168
let () =
  let red = ref 0 in
  let rec charlist_of_string str n i =
    if i = n then []
    else if str.[i] = 'R' then (red := !red + 1; 'R' :: charlist_of_string str n (i+1))
    else 'W' :: charlist_of_string str n (i+1)  in
  let rec count lst target n i =
    if i = n then 0
    else match lst with
      | [] -> 0
      | h :: t -> if h = target then 1 + count t target n (i+1) else count t target n (i+1) in
  Scanf.scanf "%d\n%s\n" @@ fun n s ->
  let lst = charlist_of_string s (String.length s) 0 in
  Printf.printf "%d\n" (count lst 'W' (!red) 0)

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

int main(){

	int n, zero[20001], cnt_two, cnt_five;

	cnt_two = 0;
	cnt_five = 0;

	for(int i=1; i<=20000; i++){
		n = i;
		while(n % 2 == 0){
			n /= 2;
			cnt_two++;
		}
		n = i;
		while(n % 5 == 0){
			n /= 5;
			cnt_five++;
		}
		zero[i] = min(cnt_two, cnt_five);
	}

	while(cin >> n){
		if(n == 0) break;
		cout << zero[n] << endl;
	}

	return 0;

}

Measured memory_bytes: 1236
macro_rules! read {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}

fn read_trim() -> String {
    read!().trim().to_owned()
}

fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read!().split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}

fn main() {
    let n: i32 = read_to_vec()[0];
    println!("{}", n*(n+1)/2);
}

Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int dp[100100];

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

Measured memory_bytes: 4028
#include <algorithm>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    string ans;
    for (int i = 0, n = s.length(); i < n; i += 2)
    {
        ans.push_back(s[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;
int a[105];
int mp[1005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y;
    cin>>x>>y;
    if(y%2)
    {
        cout<<"No"<<'\n';
    }
    else
    {
        int l=x*2;
        int r=x*4;
        if(y<=r&&y>=l)
        {
            cout<<"Yes"<<'\n';
        }
        else
            cout<<"No"<<'\n';
    }





}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
#define rep(i,a) for(i = 0;i < a;++i)
#define INF 10000000
int main(){
  int N;
  cin >> N;
  int a[200];
  
  int i = 0;
  rep(i,N) cin >> a[i];
  
  int res = INF;
  rep(i,N){
    int sum = 0;
    while(a[i]%2 == 0){
      a[i] /= 2;
      ++sum;
    }
    if(res > sum) res = sum;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main(){
	long long s, mod = 1e9+7;
	std::cin >> s;
	std::vector<long long> dp(s+1);
	dp[0] = 1;
	for(int i = 3; i <= s; i++)
		for(int j = 0; j <= i-3; j++) dp[i] = (dp[i]+dp[j])%mod;
	std::cout << dp[s] << '\n';
	return 0;
}



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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }

int lcp(const string &s1, const string &s2) {
	int cnt = 0, n = min(s1.size(), s2.size());
	REP(i, n) {
		if (s1[i] == s2[i]) cnt++;
		else break;
	}
	return cnt;
}

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	string str; cin >> str;
	int ans = 700;
	REP(i, 3) if (str[i] == 'o') ans += 100;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int x = sc.nextInt();
		int y = sc.nextInt();
		System.out.println(gcd(x,y));
	}
	//最大公約数gcdを求める
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
}				


Measured memory_bytes: 26332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1e9 + 7

template < typename T >
void printVector (const vector < T > & vec) {
	for (const T x : vec) {
		cout << x << " ";
	}
	cout << endl;
}

const int INF = 1e9 + 5;

int main() {
	int N;
	scanf ("%d", &N);
	vector < int > h (N);
	for (int & x : h) {
		scanf ("%d", &x);
	}
	vector < int > dp (N, INF);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j : {i + 1, i + 2}) {
			if (j < N){
				dp[j] = min (dp[j], dp[i] + abs (h[i] - h[j]));
			}
		}
	}
	// printVector (h);
	// printVector (dp);
	printf ("%d\n", dp[N - 1]);
	return 0;
}

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

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

    int start, end, flag = 0, length;
    length = s.size();

    for(int i = 0; i < length; i++){
        if(s.at(i) == 'A'){
            if(flag == 0){
                start = i;
                flag = 1;
            }
        }

        if(s.at(i) == 'Z'){
            end = i;
        }
    }

    cout << end - start + 1 << endl;

}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int K = in.i();
        int[] A = in.ii(N);
        
        String ans = K <= max(A) && K % gcd(A) == 0 ? "POSSIBLE" : "IMPOSSIBLE";
        out.println(ans);
    }

    static int max(int... a) {
        int m = a[0];
        for (int i = 1; i < a.length; i++) {
            if (m < a[i]) {
                m = a[i];
            }
        }
        return m;
    }

    static int gcd(int... a) {
        int g = a[0];
        for (int i = 1; i < a.length; i++) {
            int b = a[i];
            int r;
            while ((r = g % b) != 0) {
                g = b;
                b = r;
            }
            g = b;
        }
        return g;
    }
}


class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 35744
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)


struct Forest_Uni {
	vector<UL> v;
	void init(UL n) {
		v.clear();
		rep(i, n) v.push_back(i);
	}
	UL root(UL p) {
		if (v[p] == p) return p;
		return v[p] = root(v[p]);
	}
	void unite(UL a, UL b) {
		UL A = root(a);
		UL B = root(b);
		if (A != B) {
			v[A] = B;
		}
	}
};

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		vector<UL> D(N);
		vector<vector<pair<UL, UL>>> E(N);
		vector<UL> Col(N);
		vector<UL> ans(M);
		rep(i, M) ans[i] = 1000000000;
		rep(i, N) cin >> D[i];
		rep(i, M) {
			UL u, v; cin >> u >> v;
			u--; v--;
			E[u].push_back({ v, i });
			E[v].push_back({ u, i });
		}
		vector<vector<pair<UL, UL>>> Dep(N);
		Forest_Uni F; F.init(N);

		rep(i, N) {
			bool ok = false;
			for (auto &e : E[i]) {
				if (D[i] > D[e.first]) {
					Dep[e.first].push_back({ i, e.second });
					ok = true;
					break;
				}
			}
			if (!ok) {
				for (auto &e : E[i]) {
					if (D[i] == D[e.first]) {
						ok = true;
						if (F.root(i) == F.root(e.first)) continue;
						Dep[e.first].push_back({ i, e.second });
						F.unite(i, e.first);
						break;
					}
				}
			}
			if (!ok) {
				cout << -1 << endl; return;
			}
		}

		queue<pair<UL, UL>> q;

		vector<pair<UL, UL>> li(N);
		rep(i, N) li[i] = { D[i], i };
		sort(li.begin(), li.end());
		rep(i, N) {
			UL p = li[i].second;
			if (Col[p]) continue;
			q.push({ p, 1 });
			while (q.size()) {
				auto pp = q.front(); q.pop();
				Col[pp.first] = pp.second;
				for (auto & ppp : Dep[pp.first]) {
					if (D[pp.first] == D[ppp.first]) {
						q.push({ ppp.first, 3 - pp.second });
						ans[ppp.second] = D[pp.first];
					}
					else {
						q.push({ ppp.first, pp.second });
						ans[ppp.second] = D[ppp.first] - D[pp.first];
					}
				}
			}
		}
		rep(i, N) {
			if (Col[i] == 1) cout << "W"; else cout << "B";
		}cout << endl;
		rep(i, M) {
			cout << ans[i] << endl;
		}
	}

	
	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 17276
import sys

w,h = map(int, input().split())
sumC = 0
sumR = 0
col = list(map(int, input().split()))
row = list(map(int, input().split()))
for c in col : sumC += c
for r in row : sumR += r

if sumR != sumC :
    print(0)
    sys.exit(0)

for i in range(w):
    row.sort(reverse=True)
    for j in range(h):
        if not col[i] or not row[j] : break
        row[j] -= 1
        col[i] -= 1
    if col[i] > 0 :
        print(0)
        sys.exit(0)
print(1)



Measured memory_bytes: 5720
x=int(input())
up=0
for i in range(1000):
    if (i+1)**5-i**5>10**9:
        up=i
        break
for a in range(-up-1,up+1):
    for b in range(-up-1,up+1):
        if a**5-b**5==x:
            print(a,b)
            exit()


Measured memory_bytes: 63856
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <sstream>
#include <iostream>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
ll mypow(ll x, ll n) {
  if(n == 0) return 1;
  if(n % 2 == 0) return mypow(x*x%MOD, n/2);
  return mypow(x*x%MOD, n/2) * x % MOD;
}

ll vs[100000+10];

ll inv[100000+10];
ll invsum[100000+10];

int main(void) {
  for(int i = 1; i <= 100000; ++i) {
    inv[i] = mypow(i, MOD-2);
    invsum[i] = invsum[i-1] + inv[i];
  }

  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &vs[i]);
  }
  ll res = 0;
  REP(i, n) {
    // vs[i]の寄与の期待値は、
    //   (0番目が取り除かれる時にi番目まで繋がってる確率) * vs[i]
    // + (1番目が取り除かれる時にi番目まで繋がってる確率) * vs[i]
    // ...
    // で、取り除かれる時に繋がってる確率は、1/(距離+1)
    ll p = (invsum[i+1] + invsum[n-i] - 1) % MOD;
    res = (res + p * vs[i] % MOD) % MOD;
  }
  REP(i, n) {
    res = res * (i+1) % MOD;
  }
  
  cout << res << endl;
  return 0;
}


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

#define PB push_back
#define all(a) a.begin(), a.end()
#define REP(type,i, a, n) for ( type i = a; i < n; i++)

#define vi vector<int>
#define vii vector<pair<int, int> >
#define vl vector<long long>
#define vvi vector< vector<int> >

typedef long long ll;

// for debugging output uncomment below line 
// #define DBG
//NOTE : COMMNET ABOVE LINE BEFORE SUBMITTING

#ifdef DBG
	#define dout if(true) cout
	#define dfor if(true) REP
#else
	#define dout if(false) cout
	#define dfor if(false) REP
#endif


using namespace std;

void optimizeIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

//==================================================================================///////////////////
///                  CLASHER
//////////////==========================================================//////////////////////////////

int main() {
    optimizeIO();
    int n;
     cin >> n;
     vi a(n),b(n);

     REP(int,i,0,n){
         int t;
         cin >> t;
         a[i] = t;
         b[i] = t;
     }

     sort(all(a));
     int counter = 0;
     REP(int ,i,0,n){
         if(a[i] != b[i]){
             counter++;
             if(counter > 2){
                 cout <<"NO";
                 return 0;
             }
         }
     }
     cout << "YES";
     

    return 0;

}



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

typedef pair<string, int> P;

signed main() {
  int n, q;
  cin >> n >> q;

  queue<P> Q;
  for ( int i = 0; i < n; i++ ) {
    string name;
    int time;
    cin >> name >> time;
    Q.push(P(name, time));    
  }

  int sum = 0;
  while ( !Q.empty() ) {
    P p = Q.front(); Q.pop();
    string name = p.first;
    int time  = p.second;

    sum += min(time, q);

    if ( time <= q ) {
      cout << name << " " << sum << endl;
    } else {
      Q.push(P(name, time-q));
    }
  }
  
  return 0;
}



Measured memory_bytes: 6308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] string = line.split(" ");
		int[] is = new int[string.length];
		for (int i = 0; i < is.length; i++) {
			is[i] = Integer.parseInt(string[i]);
		}

		int W = is[0];
		int H = is[1];
		int x = is[2];
		int y = is[3];
		int r = is[4];

		if ((r <= x && x <= (W - r)) && (r <= y && y <= (H - r))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 26236