akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;

void solve() {
    cin >> N;
    ll T = 1;
    ll A = 1;
    for (int i = 0; i < N; ++i) {
        ll t, a;
        cin >> t >> a;
        ll n = max((T - 1) / t + 1, (A - 1) / a + 1);
        T = n * t;
        A = n * a;
    }
    cout << A + T << endl;
}

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

dp = [[0 for i in range(2)] for i in range(N+1)]

dp[0][0] = 0
dp[0][1] = -10000000

for i in range(N):
    dp[i+1][0] = max(dp[i][0] + A[i],dp[i][1] - A[i])
    dp[i+1][1] = max(dp[i][0] - A[i],dp[i][1] + A[i])
print(dp[N][0])

Measured memory_bytes: 27084
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 100005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll b) { if (a % b == 0)	return (a / b);	return (a / b + 1);}
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll x, k, d;
	cin >> x >> k >> d;
	ll ans = 0;
	ll v = abs(x) / d;
	if (k < v)
		cout << abs(x) - k*d;
	else
	{
		if ((v - k) % 2 == 0)
			cout << abs(x) - v*d;
		else
			cout << d - abs(x) + v*d;
	}



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#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> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  int n; cin >> n;
  V a(n); cin >> a;

  if (a[0] != 0) {
    cout << -1 << "\n";
    return 0;
  }

  ll ans = 0;
  vector<Pll> v({{0, 1}});

  rep(i, n) {
    if (a[i] > v.back().first + 1) {
      cout << -1 << "\n";
      return 0;
    }
    else if (a[i] == v.back().first + 1) {
      v.emplace_back(a[i], 1);
    }
    else if (a[i] == v.back().first) {
      v.back().second++;
    }
    else if (a[i] < v.back().first) {
      for (auto [x, y] : v) {
        ans += x * max(y-1, 0ll);
      }
      ans += v.back().first;
      v.clear();
      v.emplace_back(a[i], 1);
    }
  }

  for (auto [x, y] : v) {
    ans += x * max(y-1, 0ll);
  }
  ans += v.back().first;

  cout << ans << "\n";
  return 0;
}


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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[ ";
    for (auto a : v) os << a << " ";
    os << "]";
    return os;
}

int main() {
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;




int main() {
    int grid[3][3]={};

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            scanf("%d",&grid[i][j]);
        }
    }

    for(int i=0;i<3;i++){
        int min=100000000;
        for(int j=0;j<3;j++){
            if(grid[i][j]<min){
                min=grid[i][j];
            }
        }
        if(min>=1){
            for(int j=0;j<3;j++){
                grid[i][j]-=min;
            }
        }
    }
    for(int i=0;i<3;i++){
        int min=10000000;
        for(int j=0;j<3;j++){
            if(grid[j][i]<min){
                min=grid[j][i];
            }
        }
        if(min>=1){
            for(int j=0;j<3;j++){
                grid[j][i]-=min;
            }
        }
    }

    bool isOk=true;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(grid[i][j]!=0){
                isOk=false;
            }
        }
    }

    if(isOk){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
R,C,N = gets.split.map(&:to_i)
pts = []

def onedge(x,y)
  case
  when y == 0; x
  when x == R; R + y
  when y == C; R + C + R - x
  when x == 0; R + C + R + C - y
  else         nil
  end
end

(1..N).each{ |i|
  x1,y1,x2,y2 = gets.split.map(&:to_i)
  r1 = onedge(x1,y1); r2 = onedge(x2,y2)
  if r1 && r2
    #p "#{i}: #{x1},#{y1} -> #{r1} / #{x2},#{y2} -> #{r2}"
    pts << [r1,i]; pts << [r2,i]
  end
}

pts.sort_by!{ |r,i| r }
#p pts.map{ |r,i| i }

stack = []
pts.map{ |r,i|
  #p [r,i], stack
  if stack.size > 0 && stack[-1] == i
    stack.pop
  else
    stack << i
  end
}

puts stack.size == 0 ? "YES" : "NO"

Measured memory_bytes: 27000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <ctime>
#include <string>
#include <cstring>
#define mp make_pair
#define pb push_back
#define NAME ""
#define y1 y1_423
#define list lista

using namespace std;

typedef long long ll;
typedef long double ld;

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

template<typename T>
ostream& operator << (ostream& cout, const set<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T>
ostream& operator << (ostream& cout, const multiset<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T1, typename T2>
ostream& operator << (ostream& cout, const pair<T1, T2> &a) {
	return cout << "(" << a.first << "; " << a.second << ")";
}

const int nmax = 2000 * 1000;
const int inf = 2000 * 1000 * 1000;
const ll infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const ld pi = acos(-1.0);

ll n;
ll sum = 0, a[nmax], b[nmax];

int main() {
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	//freopen(NAME".in", "r", stdin);freopen(NAME".out", "w", stdout);
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		sum += a[i];
	}
	if (sum % (n * (n + 1) / 2) != 0) {
		cout << "NO\n";
		return 0;
	}
	ll cnt = sum /= (n * (n + 1)) / 2;
	for (int i = 0; i < n; i++) {
		b[i] = a[i] - a[(i + n - 1) % n] - cnt;
		if (b[i] == 0) {
			continue;
		}
		if (b[i] > 0) {
			cout << "NO\n";
			return 0;
		}
		b[i] = -b[i];
		if (b[i] % n != 0) {
			cout << "NO\n";
			return 0;
		}
		sum -= b[i] / n;
	}
	if (sum != 0) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	return 0;
}



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

int main() {
    int N, ans = 1;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; ++i) {
        cin >> d.at(i);
    }
    sort(d.begin(), d.end(), greater<int>());

    int current = d[0];
    for (auto s : d) {
        if (current > s) {
            ans++;
            current = s;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1000000007, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int N,K;
	cin>>N>>K;
	vector<int> a(N); for(auto& e:a)cin >> e;
	int s = 0;
	REP(i,N){
		s += a[i];
	}
	vector<int>v;
	for(int i = 1;i*i<=s;i++){
		if(s % i)continue;
		v.push_back(s/i);
		if(i != s/i)v.push_back(i);
	}
	sort(ALL(v));
	reverse(ALL(v));
	for(auto i:v){
		int sum = 0;
		priority_queue<int,vector<int>,greater<int>>que;
		REP(j,N){
			int t = a[j] % i;
			sum += t;
			que.push(t);
		}
		if(sum%i)continue;
		int num = N - sum / i;
		if(que.size()<num)continue;
		int ans = 0;
		REP(k,num){
			ans += que.top();
			que.pop();
		}
		if(ans <= K){
			cout<<i<<endl;
			return 0;
		}
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
long long K;
vector<pair<int, int>> ab;

void solve() {
  sort(ab.begin(), ab.end());
  long long k = 0;
  for (int i = 0; i < N; i++) {
    k += ab[i].second;
    if (k >= K) {
      cout << ab[i].first << endl;
      break;
    }
  }
}

int main() {
  cin >> N >> K;
  ab.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> ab[i].first >> ab[i].second;
  }
  solve();
}

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


void solve(std::string S){
    if (S == "ABC") cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3628
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::{BTreeMap, BTreeSet};

fn main() {
    input!{
        s: chars,
        t: chars,
    }

    let ans = || {
        let mut mm = BTreeMap::new();
        for i in 0..s.len() {
            if let Some(c) = mm.get(&s[i]) {
                if *c != t[i] {
                    return false;
                }
                continue;
            }
            mm.insert(s[i], t[i]);
        }

        mm.values().collect::<BTreeSet<_>>().len() == mm.len()
    };

    println!("{}", if ans() { "Yes" } else { "No" });
}


Measured memory_bytes: 6396
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

int W, H;
vector<string> mat;

string dp[100][100];

string maxstr(string s1, string s2) {
	int len1 = (int)s1.length();
	int len2 = (int)s2.length();
	if (len1 < len2) return s2;
	if (len1 > len2) return s1;
	
	for (int i = 0; i < len1; i++) {
		if (s1[i] < s2[i]) return s2;
		if (s1[i] > s2[i]) return s1;
	}
	
	return s1;
}

string zrm(string s) {
	if (s[0] == '0') s = s.substr(1);
	return s;
}

bool isdig(char c) {
	if ('0' <= c && c <= '9') return true;
	return false;
}

void solve() {
	for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) dp[i][j] = "";
	
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (!isdig(mat[i][j])) continue;
			if (j == 0) {
				dp[i + 1][j] = zrm(dp[i][j] + mat[i][j]);
			} else {
				dp[i + 1][j] = maxstr(zrm(dp[i + 1][j - 1] + mat[i][j]),
									  zrm(dp[i][j] + mat[i][j]));
			}
		}
	}
	
	string ans = "";
	for (int i = 0; i <= H; i++) {
		for (int j = 0; j < W; j++) {
			ans = maxstr(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
}

int main() {
	while (1) {
		cin >> W >> H; if (W==0 && H==0) break;
		mat.assign(H, "");
		for (int i = 0; i < H; i++) {
			cin >> mat[i];
		}
		
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e5+5;
const int inf=(1ll<<31)-1;
#define lson (rt<<1)
#define rson (rt<<1|1)
int mini[maxn*4];
void upd(int rt,int l,int r,int loc,int v){
    if(l==r)mini[rt]=v;
    else{
        int mid=(l+r)/2;
        if(loc<=mid)upd(lson,l,mid,loc,v);
        else upd(rson,mid+1,r,loc,v);
        mini[rt]=min(mini[lson],mini[rson]);
    }
}
int find(int rt,int l,int r,int x,int y){
    if(x<=l&&r<=y)return mini[rt];
    int mid=(l+r)>>1;
    if(y<=mid)return find(lson,l,mid,x,y);
    if(x>mid)return find(rson,mid+1,r,x,y);
    else{
        return min(find(lson,l,mid,x,mid),
        find(rson,mid+1,r,mid+1,y));
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    rep(i,0,(n<<2))mini[i]=inf;
    rep(i,1,q){
        int op,x,y;
        cin>>op>>x>>y;
        if(op)cout<<find(1,1,n,x+1,y+1)<<endl;
        else upd(1,1,n,x+1,y);
    }

}

/* 
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
 */


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;
 
    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
 
    vvl dp(n+1, vl(n+1));  // dp[l][r] : aの区間[l,r)から始めて二人が最適に行動したときのx-yの値
    exrep(len, 1, n) {
        for(ll l = 0; l + len <= n; l++) {
            ll r = l + len;
            // 先手
            if((n - len)%2 == 0) {
                dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1]);
            }
            // 後手
            else {
                dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1] - a[r-1]);
            }
        }
    }
    
    out(dp[0][n]);
    re0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
using Graph = vector< vector<int> >;
vector<bool> seen;
int ans;

void dfs(const Graph G,int v){
    seen[v] = true;
    bool check = true;
    for(int i=0;i<G.size();++i){
        if(!seen[i]){
            check = false;
            break;
        }
    }
    if(check) ans++;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        dfs(G,next_v);
    }
    seen[v] = false;
    
}

int main(){
    int n,m;
    cin >> n >> m;
    Graph G(n);
    for(int i=0;i<m;++i){
        int a,b; cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.assign(n,false);//全頂点を未訪問に初期化 特定の値で初期化したいとき、assign(n,val)
    dfs(G,0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
INF = 10 ** 12
n = int(input())
a = list(map(int, input().split()))
g = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v = map(int, input().split())
    g[u - 1].append(v - 1)
    g[v - 1].append(u - 1)
dp = [INF] * n
k = [None] * n
ans = [0] * n
s = [0]
while s:
    p = s.pop()
    if k[p] == None:
        s.append(p)
        idx = bisect_left(dp, a[p])
        k[p] = (idx, dp[idx])
        dp[idx] = a[p]
        ans[p] = bisect_left(dp, INF)
        for node in g[p]:
            if k[node] == None:
                s.append(node)
    else:
        idx, x = k[p]
        dp[idx] = x
for x in ans:
    print(x)


Measured memory_bytes: 135540
x=int(input())
b=0;
lst=[]
acs=0
was=0
res=0
tles=0
while(b<x):
    new=input()
    lst.append(new)
    b+=1
for c in lst:
    if(c=='AC'):
        acs+=1
    if(c=='WA'):
        was+=1
    if(c=='RE'):
        res+=1
    if(c=='TLE'):
        tles+=1
print('AC x '+str(acs))
print('WA x '+ str(was))
print('TLE x ' +str(tles))
print('RE x ' +str(res))  

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

int main()
{
	int n;
	cin >> n;
	if (n == 25)cout << "Christmas" << endl;
	else if (n == 24)cout << "Christmas Eve" << endl;
	else if (n == 23)cout << "Christmas Eve Eve" << endl;
	else cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

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

#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define fi first
#define se second
#define sqrt(x) sqrt(abs(x))
#define sqr(x) ((x) * (x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define fill(x, y) memset(x, y, sizeof(x))
#define mp make_pair
#define pb emplace_back
#define popcnt __builtin_popcount
#define ctz __builtin_ctz

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
template <class T> using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T>
istream& operator >> (istream &in, vector <T> &a) {
    for (T &i: a) in >> i;
    return in;
}

template <class T>
ostream& operator << (ostream &out, vector <T> &a) {
    for (T &i: a) out << i << ' ';
    return out;
}

template <class T>
ostream& operator << (ostream &out, set <T> &a) {
    for (auto &i: a) out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator >> (istream &in, pair <T, U> &p) {
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator << (ostream &out, pair <T, U> &p) {
    out << p.first << ' ' << p.second;
    return out;
}

void fastIO() {
    ios_base:: sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
}

string s;

signed main() {
    fastIO();

    cin >> s;
    string t = s;
    sort(all(s));
    sort(all(t), greater <char> ());

    if (s == t) cout << "No";
    else cout << "Yes";

    return 0;
}

/// ЗАПУСКАЕМ ГУСЯ:
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */



Measured memory_bytes: 256
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    ll a=in(),b=in();
    ll x=abs(a-b);
    if(x%2==0)cout<<max(a,b)-x/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	int n = s.length()-2;
	if(s[0]==s[n+1])
		n--;
	if(n&1)
		cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int main()
{
	int n=io::F(),a=io::F(),b=io::F();
	int t=0;
	while(a+1!=b)
	{
		if(t==0)++a;
			else --b;
		t^=1;
	}
	if(t)puts("Alice");
		else puts("Borys");
	return 0;
}




Measured memory_bytes: 256
import math
N,M = map(int,input().split())
if abs(N-M) > 1:
    ans = 0
else:
    if abs(N-M) == 1:
        a = math.factorial(N)
        b = math.factorial(M)
        ans = a*b
    elif abs(N-M) == 0:
        a = math.factorial(N)
        b = math.factorial(M)
        ans = 2*a*b
ans=ans%(10**9+7)
print(ans)

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

int main() {
	int64_t n, k; cin >> n >> k;
	int64_t a[n], b[n]; for(int i = 0; i < n; ++i) cin >> a[i] >> b[i];
	int64_t ans = 0;
	for(int i = 0; i < n; ++i) {
		if((a[i] | k) == k) {
			ans += b[i];
		}
	}
	for(int64_t i = 0; i < 40; ++i) {
		if((1ll << i) > k) break;
		if(not (k >> i & 1)) continue;
		int64_t mask = (k & (~(1ll << i))) | ((1ll << i) - 1);
		int64_t sum = 0;
		for(int j = 0; j < n; ++j) {
			if((a[j] | mask) == mask) {
				sum += b[j];
			}
		}
		ans = max(ans, sum);
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265

int capacity[202][202];
vector<int> adj[202];
int nd , e;
int source , sink;
int parent[202];

bool bfs() {
    bool visited[nd];
    memset(visited , false , sizeof(visited));

    parent[source] = -1;
    queue<int> qu;
    qu.push(source);
    visited[source] = true;
    int s;

    while (!qu.empty()) {
        s = qu.front();
        qu.pop();

        for (auto it : adj[s]) {
            if (!visited[it] && capacity[s][it] > 0) {
                qu.push(it);
                visited[it] = true;
                parent[it] = s;
            }
        }
    }
    return (visited[sink] == true);
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<PII> vec1 , vec2;
    int v;
    int x , y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        vec1.pb({x , y});
    }
    int m = n;
     for (int i = 0; i < n; i++) {
        cin >> x >> y;
        vec2.pb({x , y});
    }
    for (int i = 0; i < n; i++) {
        adj[0].pb(i + 1);
        capacity[0][i + 1] = 1;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (vec1[i].first < vec2[j].first && vec1[i].second < vec2[j].second) {
                adj[i + 1].pb(n + j + 1);
                capacity[i + 1][n + j + 1] = 1;
            }
            adj[n + j + 1].pb(m + n + 1);
            capacity[n + j + 1][m + n + 1] = 1;
        }
    }
    nd = m + n + 2;
    source = 0;
    sink = n + m + 1;

    int flow = 0, max_flow = 0;
    int u;

    while (bfs()) {
        flow = INT_MAX;
        v = sink;
        while (parent[v] != -1) {
            u = parent[v];
            flow = min(flow , capacity[u][v]);
            v = u;
        }
        v = sink;
        while (parent[v] != -1) {
            u = parent[v];
            capacity[u][v] -= flow;
            capacity[v][u] += flow;
            adj[v].pb(u);
            v = u;
        }
        max_flow += flow;
    }

    cout << max_flow << endl;

    return 0;
}


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

int main()
{
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    double h_angle, m_angle, h_y,h_x,m_y, m_x;
    h_angle = ((30 * h + 30 * m / 60) * (-1) + 90)*PI/180;
    m_angle = ((6 * m) * (-1) + 90)*PI/180;
    h_y = a * sin(h_angle);
    h_x = a * cos(h_angle);
    m_y = b * sin(m_angle);
    m_x = b * cos(m_angle);
    double l = sqrt((h_y - m_y) * (h_y - m_y) + (h_x - m_x) * (h_x - m_x));
    cout << fixed << setprecision(10) << l << endl;
    return 0;
}

Measured memory_bytes: 4100
#include <stdio.h>
#include<stdlib.h>
  
#define N 100000
#define INF 1000000



typedef struct{
    int go,back,cost;
}Date;
  
int n,d[N];
Date a[500000];
void root(int);
  
int main(void){
    int i,j,u,k,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++) {
        scanf("%d%d",&u,&k);
        for(j=0;j<k;j++){
            a[count].back=u;
            scanf("%d%d",&a[count].go,&a[count].cost);
            count++;
        }
    }
    root(count);
    for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);
    return 0;
}



void root(int b){
    int i,flag=1;
      
    for(i=0;i<n;i++) d[i]=INF;
    d[0]=0;
      
    while(flag!=0){
        flag=0;
        for(i=0;i<b;i++){
            if(a[i].cost+d[a[i].back]<d[a[i].go]){
                d[a[i].go]=a[i].cost+d[a[i].back];
                flag=1;
            }
        }
    }
}



Measured memory_bytes: 7588
#include<stdio.h>
int main(){
	int n,a=0,b=0;
	char m;
	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++){
		scanf("%c",&m);
		if(m=='R'){
			a++;
		}
		else{
			b++;
		}
	}
	if(a>b){
		printf("Yes");
	}
	else{
		printf("No");
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,-1,0,1};

struct State{
    int pa,pb,pc;
};

const int N = 16*16;
const int INF = 19191919;
int dp[N][N][N];

int main(){
    int w,h,n;
    while(cin >>w >>h >>n,w){
        cin.ignore();
        vector<string> f(h);
        rep(i,h) getline(cin, f[i]);

        auto cv = [&](pi p){
            return p.fi*w+p.se;
        };

        int sa=0,sb=0,sc=0,ga=0,gb=0,gc=0;
        rep(i,h)rep(j,w){
            if(f[i][j]=='a') sa = cv({i,j});
            if(f[i][j]=='b') sb = cv({i,j});
            if(f[i][j]=='c') sc = cv({i,j});
            if(f[i][j]=='A') ga = cv({i,j});
            if(f[i][j]=='B') gb = cv({i,j});
            if(f[i][j]=='C') gc = cv({i,j});
        }

        auto cand = [&](int p){
            int y = p/w, x = p%w;

            vector<int> ret;
            ret.pb(p);

            rep(d,4){
                int ny = y+dy[d], nx = x+dx[d];
                if(0<=ny && ny<h && 0<=nx && nx<w && f[ny][nx]!='#') ret.pb(cv({ny,nx}));
            }
            return ret;
        };


        rep(i,N)rep(j,N)rep(k,N) dp[i][j][k] = INF;
        dp[sa][sb][sc] = 0;
        queue<State> que;
        que.push({sa,sb,sc});
        while(!que.empty()){
            State now = que.front();
            que.pop();

            vector<int> da = cand(now.pa), db = cand(now.pb), dc = cand(now.pc);

            for(int A:da)for(int B:db)for(int C:dc){
                if(B != 0){
                    if(B == A) continue;
                    if(now.pa == B && now.pb == A) continue;
                }
                if(C != 0){
                    if(C == A || C == B) continue;
                    if(now.pa == C && now.pc == A) continue;
                    if(now.pb == C && now.pc == B) continue;
                }

                if(dp[A][B][C] > dp[now.pa][now.pb][now.pc]+1){
                    dp[A][B][C] = dp[now.pa][now.pb][now.pc]+1;
                    que.push({A,B,C});
                }
            }
        }
        cout << dp[ga][gb][gc] << endl;
    }
    return 0;
}



Measured memory_bytes: 71536
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using static System.Math;
using static System.Console;
class Simple
{
    int N;
    int[,] A;
    void Solve() {
        //input
        N = io.Int;
        A = new int[2, N];
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < N; ++j) {
                A[i, j] = io.Int;
            }
        }
        //cal
        var bLine = new int[N];
        var acc = 0;
        for (int i = N - 1; i >= 0; --i) {
            acc += A[1, i];
            bLine[i] = acc;
        }
        acc = 0;
        var ans = int.MinValue;
        for (int i = 0; i < N; ++i) {
            acc += A[0, i];
            ans = Max(ans, acc + bLine[i]);
        }
        //ret
        WriteLine(ans);

    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() { Solve(); io.writeFlush(); }
}
class SimpleIO
{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
read = sys.stdin.read

N, *ab = map(int, read().split())
a, b = zip(*zip(*[iter(ab)] * 2))

graph = csr_matrix(([1] * (N - 1), (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False, indices=[1, N])
d1 = distance[0][1:]
dn = distance[1][1:]

Fennec = np.count_nonzero(d1 <= dn)

if Fennec > N - Fennec:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 36804
sss = input().split(' ')
while not sss[1] == '?':
	a = int(sss[0])
	b = int(sss[2])
	op = sss[1]
	if op == '+': ans = a + b
	elif op == '-': ans = a - b
	elif op == '*': ans = a * b
	elif op == '/': ans = a // b
	print('{0}'.format(ans))
	sss = input().split(' ')


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  double t, x;
  while (cin >> t >> x) {
    printf("%.10lf\n", t / x);
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tc() ll T;cin>>T;while(T--)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    /*-----------------Code Begins Here------------------*/
    
    ll a,b,c,k1; cin>>a>>b>>c>>k1;
    ll ans;
    ll k=b,l=c,count1=0,count2=0;
    if(b<=a){
        while(k<=a){
            k*=2;
            count1++;
        }
    }
    if(c<=k){
        while(l<=k){
            l*=2;
            count2++;
        }
    }
    ans= count1+count2;
    if(ans<=k1) cout<<"Yes";
    else cout<<"No";
    
    /*------------------Code Ends Here-------------------*/
    
    return 0;
}

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

s = []

A = "abcdefghijklmnopqrstuvwxyz"

def ss(n):
    if n == 1:
        return [[0]]
    tt = ss(n-1)
    res = []
    for t in tt:
        m = max(t)
        for i in range(m + 2):
            res.append(t + [i])
    return res

for s in ss(N):
    S = ''.join([A[i] for i in s])
    print(S)


Measured memory_bytes: 25292
#include<bits/stdc++.h>
using namespace std;
#define N 600010
int v[N],w[N],nxt[N],h[N],ec,d[N],n,fa[N],r1,r2,ans[N],cur[N],f[N],ab[N],ct,vis[N];
void add(int x,int y){v[++ec]=y;f[ec]=x;nxt[ec]=h[x];h[x]=ec;}
void adj(int x,int y){add(x,y);add(y,x);}
void dfs(int x){
	for(int i=cur[x];i;i=cur[x]){
		cur[x]=nxt[i];
		if(!vis[i]&&!vis[i^1]){
			vis[i]=vis[i^1]=1;
			if((x<=n&&x&&v[i]>n)||(x>n&&v[i]<=n&&v[i]))ab[++ct]=i;
			dfs(v[i]);
		} 
	}
}
int main(){
	ec=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&fa[i]);
		if(fa[i]!=-1){
			d[fa[i]]++;
			adj(fa[i],i);
		}
		else r1=i;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&fa[i+n]);
		if(fa[i+n]!=-1){
			d[fa[i+n]+n]++;
			adj(fa[i+n]+n,i+n);
		}
		else r2=i+n;
	}
	for(int i=1;i<=n;i++)
		if((d[i]^d[i+n])&1){
			printf("IMPOSSIBLE");
			return 0;
		}
	printf("POSSIBLE\n");
	for(int i=1;i<=n;i++)
		if(d[i]%2==0)adj(i,i+n);
	adj(0,r1);adj(0,r2);
	memcpy(cur,h,sizeof(h));
	dfs(0);
	for(int i=1;i<=ct;i++){
		if(v[ab[i]]>n)ans[f[ab[i]]]=1;
		else if(v[ab[i]]<=n)ans[v[ab[i]]]=-1;
	}
	for(int i=1;i<=n;i++)
		printf("%d ",ans[i]);
}

Measured memory_bytes: 35584
import java.util.*

// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun main(args: Array<String>) {
  val (n, m) = fastReadInts(2)
  val label = readLine()!!
  val graph = Array(n, { mutableListOf<Int>() })
  repeat(m) {
    val (v1Input, v2Input) = fastReadInts(2)
    val v1 = v1Input - 1
    val v2 = v2Input - 1
    if (v1 != v2) {
      graph[v1].add(v2)
      graph[v2].add(v1)
    } else {
      graph[v1].add(v1)
    }
  }

  val aCount = IntArray(n)
  val bCount = IntArray(n)
  for (v in 0 until n) {
    for (u in graph[v]) {
      if (label[u] == 'A') {
        aCount[v]++
      } else {
        bCount[v]++
      }
    }
  }

  val q = Stack<Int>()
  for (v in 0 until n) {
    q.push(v)
  }

  val isBad = BooleanArray(n)
  while (q.isNotEmpty()) {
    val v = q.pop()
    if (isBad[v]) continue
    if (aCount[v] == 0 || bCount[v] == 0) {
      isBad[v] = true
      for (u in graph[v]) {
        if (u != v && !isBad[u]) {
          q.push(u)
          if (label[v] == 'A') {
            aCount[u]--
          } else {
            bCount[u]--
          }
        }
      }
    }
  }

  if (isBad.all { it }) {
    println("No")
  } else {
    println("Yes")
  }
}


Measured memory_bytes: 86428
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K;
  cin>>N>>K;
  if(N==1){
    cout<<1<<endl;
  }
  else{
    int i =1;
    while (N>=pow(K,i)) {
        i+=1;
    }
    cout<<i<<endl;
  }
}


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

long long int prime(long long int x) {
	long long int sq = sqrt(x) ;
	bool ok = true ;
	for(int i = 2 ; i < sq ; i ++){
		if(x%i == 0 ){
			ok = false ;
			break ;
		}
	}
	if(ok) return x ;
	else return prime(x+1) ;
}

int main(){
	long long int x ;
	cin >> x;
	
	cout << prime(x) << endl ;
	
	return 0 ;
}

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

int main(){
    string s;
    cin>>s;
    long ans=0,tans=0;
    string s2=s;
    //W to left
    ans=0;
    int foundW=0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i]=='W'){
            ans+=i-foundW;
            ++foundW;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}
map<ll,int> mli; 
ll dfs(map<ll,int>::iterator itr, int mul){
    if(itr == mli.end()){
        if(mul == 1) return 1;
        else return 0;
    }
    ll res = 0;
    for(int i = 0;i < itr -> second +1; i++){
        if(mul % (i + 1) == 0){
            res += dfs(++itr, mul/(i + 1));
            itr--;
        }
    }
    return res;
}
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    rep(i,n){
        for(auto u : prime_factorize(i+1)){
            mli[u.first] += u.second;
        }
    }
    cout << dfs(mli.begin(), 75) << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fr(i, n) for (ll i = 0; i < n; i++)
#define frab(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 2e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ll N = 1e6 + 10;



int main() {
    //freopen("a.in", "r", stdin);
    int n, a, b;
    cin >> n >> a >> b;
    if (abs(b - a) % 2)
        cout << "Borys";
    else
        cout << "Alice";
}


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

const int MaxD=1e4;
const int MaxS=1e4;
const int MaxT=1e4;
int main(){
	int D, S, T;
	scanf("%d %d %d\n",&D,&S,&T);
	puts((D<=S*T)?"Yes":"No");
}

Measured memory_bytes: 3604
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn dfs(v: usize, g: &Vec<Vec<usize>>, memo: &mut Vec<i32>, s: i32) {
    if memo[v] >= 0 {
        return;
    }
    memo[v] = s;
    for t in g[v].iter() {
        dfs(*t, g, memo, s+1);
    }
}

fn dfs2(v: usize, g: &Vec<Vec<usize>>, memo: &Vec<i32>, visited: &mut Vec<bool>, s: i32) -> i32 {
    if memo[v] <= s {
        return memo[v];
    } else if visited[v] {
        if g[v].len() == 1 {
            return memo[v] - 1;
        } else {
            return memo[v];
        }
    }
    visited[v] = true;
    let mut res = s;
    for t in g[v].iter() {
        res = cmp::max(res, dfs2(*t, g, memo, visited, s+1));
    }
    res
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let u = line[1] - 1;
    let v = line[2] - 1;

    let mut g = vec![Vec::new(); n];
    for i in 0..n-1 {
        let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = line[0] - 1;
        let b = line[1] - 1;
        g[a].push(b);
        g[b].push(a);
    }    
    let mut memo = vec![-1; n];
    dfs(v, &g, &mut memo, 0);
    let mut visited = vec![false; n];
    let ans = dfs2(u, &g, &memo, &mut visited, 0);
    println!("{}", ans);
}


Measured memory_bytes: 14588
h, w = list(map(int, input().split()))
power = [list(map(int, input().split())) for i in range(10)]

for i in range(10):
    for j in range(10):
        for k in range(10):
            power[j][k] = min(power[j][i] + power[i][k], power[j][k])

ans = 0
for i in range(h):
    wall = list(map(int, input().split()))
    for item in wall:
        if item < 0:  continue
        ans += power[item][1]
print(ans)

Measured memory_bytes: 73464
MOD = 1000000007

N, M = (int(x) for x in input().split())

pow = [0] * (N + 1)
dp = [0] * (N + 1)

pow[0] = 1

for i in range(1, N + 1):
    pow[i] = pow[i - 1] * 2
    pow[i] %= MOD

dp[0] = 1

for i in range(1, M + 1):
    dp[i] = pow[i]

dp[M] -= 1

for i in range(M + 1, N + 1):
    dp[i] = dp[i - 1] + (dp[i - 1] - dp[i - 1 - M])
    dp[i] %= MOD

print((pow[N] - dp[N] + MOD) % MOD)



Measured memory_bytes: 13304
import math
from fractions import Fraction
A, B, H, M = map(float, input().split())
a_th = (H+M/60)/12*2.0*math.pi
#a_th = (float(H)+3.0)/6.0*math.pi 
b_th = (M/60.0)*2.0*math.pi
ｔｈ = abs(a_th-b_th)#abs(float(H)/12.0-float(M)/60.0)*math.pi*2.0
d = math.sqrt(A*A +B*B -2*A*B*math.cos(th))
print(d)

Measured memory_bytes: 73372
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

uint64_t solve(int n, uint64_t x, bool whole = false) {
	if (!n)return 1;
  if (x < 2ull&&!whole)return 0;
	if (whole)return solve(n - 1, 0, true) * 2 + 1;
	if (x > (((1ull) << (n + 2))-3)/2+1)
		return solve(n - 1, 0, true) + solve(n - 1, x - ((((1ull)<<(n+2))-3)/2+1)) + 1;
	else if (x == (((1ull) << (n + 2))-3)/2+1)
		return solve(n - 1, 0, true) + 1;
	else return solve(n - 1, x - 1);
}

int main() {
	int N;
	uint64_t X;
	std::cin >> N >> X;
	std::cout << solve(N, X) << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, i, arr[103], temp;
	
	scanf("%d", &n);
	
	for(i=0;i<n;i++)
	scanf("%d", &arr[i]);
	
	for(i=0;i<n/2;i++){
		temp=arr[i];
		arr[i]=arr[n-i-1];
		arr[n-i-1]=temp;
	}
	
	
	for(i=0;i<n-1;i++){
	printf("%d ", arr[i]);
    }
    
    printf("%d\n", arr[n-1]);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
using namespace std;
int main(void){
    ll N , K ;
    cin >> N >> K ;
    ll a[N] ;
    rep(i ,N) cin >> a[i];

    sort(a , a+N);
    ll ans = 0 ;
    rep(j , K) ans += a[j] ;

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

Measured memory_bytes: 3640