akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
const int MAXN=2*1e5+1000;
int H[MAXN];
long long int V[MAXN];

set<int> altezze;
long long int sol[MAXN];
int N;
int mappa[MAXN];
int main(){
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>H[i];
	for(int i=0;i<N;i++){
		cin>>V[i];
		mappa[H[i]]=i;
		sol[i]=V[i];
	}
	altezze.insert(H[0]);
	set<int>::iterator it;
	
	for(int i=1;i<N;i++){
		it=altezze.upper_bound(H[i]);
		if(it!=altezze.begin()){
			it--;
			sol[i]+=sol[mappa[*(it)]];
		}
		
		altezze.insert(H[i]);
		
		it = altezze.find(H[i]);
		it++;
		while(it!=altezze.end() && sol[mappa[*(it)]]<=sol[i]){
			set<int>::iterator tmp = it;
			it++;
			altezze.erase(tmp);
		}
	}
	long long int risultato = 0;
	for(int i=0;i<N;i++)
		risultato = max(risultato, sol[i]);
	cout<<risultato;
}

Measured memory_bytes: 14336
#!/usr/bin/python

import os
import sys
import itertools

f = sys.stdin
d = {'A': (0,0), 'B': (0,1), 'C': (0,2),
     'D': (1,0), 'E': (1,1), 'F': (1,2),
     'G': (2,0), 'H': (2,1), 'I': (2,2)}

while True:
    n = int(f.readline().strip())
    if n==0: sys.exit()

    s,t,b = f.readline().split()

    dp = [dict([((j,k),0) for k in xrange(3) for j in xrange(3)]) for i in xrange(n+1)]
    dp[0][d[t]] = 1

    for i in xrange(1,n+1):
        for j in xrange(3):
            for k in xrange(3):
                # up
                x,y = max(0,j-1), k
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

                # down
                x,y = min(j+1,2), k
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

                # left
                x,y = j, max(0,k-1)
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

                # right
                x,y = j, min(2, k+1)
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

    print dp[n][d[s]]/4.**n

Measured memory_bytes: 4520
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String s = sc.next();
        String slist[] = s.split("");
        int count1 = 0;
        int count2 = 0;
        for (int i = 0; i < slist.length; ++i){
            if(slist[i].equals("R")){
                count1 += 1;
            }
            if(slist[i].equals("B")){
                count2 += 1;
            }
        }
        if(count1 > count2){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35808
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

ll rui(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n&1) ans=ans*a%MOD;
    a=a*a%MOD;
    n/=2;
  }
  return ans;
}

int main(){
  int N; cin >> N;
  vector<ll> c(N);
  rep(i,N) cin >> c[i];
  sort(all(c));
  ll A=rui(4,N-1);
  ll B=0;
  for(int i=0;i<N;i++){
    B+=c[i]*(N+1-i);
    B%=MOD;
  }
  ll ans=A*B%MOD;
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,a[20][20],p[1<<17]={},dp[1<<17]={};
  cin>>n;
  fr(i,n) fr(j,n) cin>>a[i][j];
  fr(i,n){
    fr(j,1<<i){
      p[j+(1<<i)]=p[j];
      fr(k,i) if((j>>k)&1) p[j+(1<<i)]+=a[i][k];
    }
  }
  fr(i,1<<n){
    dp[i]=p[i];
    for(int s=i&(i-1);s>0;s=i&(s-1)) dp[i]=max(dp[i],dp[s]+dp[i&(~s)]);
  }
  cout<<dp[(1<<n)-1]<<endl;
}

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

int main() {
    ll n, h;
    cin >> n >> h;
    vector<ll> a(n);
    vector<ll> b(n);
    ll amax = 0, abmax = 0;
    ll sum = 0;
    int num = 0;
    ll count = 0;
    rep(i, 0, n) cin >> a[i] >> b[i];
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    rep(i, 0, n) {
        if(b[i] >= a[0]) {
            count++;
            sum += b[i];
        }
        else break;
        if(sum >= h) {
            cout << count << endl;
            return 0;
        }
    }
    
    ll tmp = (h-sum)%a[0];
    if(tmp == 0) {
        count += (h-sum)/a[0];
    }
    else {
        count += (h-sum)/a[0]+1;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e3 + 10;
LL solve(vector<int>& v)
{
	LL sum = v[0];
	LL ans = 0;
	for (int i = 1; i < v.size(); i++)
	{
		ans += 1LL * v[i] * i - sum;
		sum += v[i];
	}
	return ans % INF;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	vector<int> v1(n), v2(m);
	for (auto& x : v1) cin >> x;
	for (auto& y : v2) cin >> y;
	cout << solve(v1) * solve(v2) % INF << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    using ld = long double;
    int n, m, d;
    cin >> n >> m >> d;
    
    ld ans = m - 1;
    if(d == 0)  ans /= n;
    else{
        ans *= 2.0 * (n - d);
        ans /= (ld)n * n;
    }
    
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

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

cnt=0
for i in range(N):
    if A[i]>=B[i]:
        cnt+=B[i]
        A[i]-=B[i]
    else:
        cnt+=A[i]
        B[i]-=A[i]
        A[i]=0
        if A[i+1]>=B[i]:
            cnt+=B[i]
            A[i+1]-=B[i]
            B[i]=0
        else:
            cnt+=A[i+1]
            A[i+1]=0
print(cnt)


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

int main()
{
    int n,t;
    cin >> n >> t;
    int m = 1e5;
    while(n--){
        int a, b;
        cin >> a >> b;
        if(b > t) continue;
        m = min(m, a);
    }
    if(m == 1e5){
        cout << "TLE" << endl;
    }else{
        cout << m << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{

    int n;

    float s[10000];
     cin >> n;

    float sum = 0;
    for(int i = 0;i < n;i++)
    {

        cin >> s[i];
        sum = sum + (1/s[i]);

    }

    cout << 1/sum;

}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forn(i, n) for (int i = 0 ; i < int(n) ; i++)
#define fore(i, s, t) for (int i = s ; i < (int)t ; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x)  cout<<it<<endl;
#define pi pair<int,int>
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y) 
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
using namespace std;
typedef long long ll;
const ll P=1e9+7;
bool is(string s){
	string ss=s;
	reverse(all(ss));
	return ss==s;
}
int main(){   
	string s;
	cin>>s;
	if(is(s) && is(s.substr(0,s.size()/2)) && is(s.substr(s.size()/2+1,s.size()/2))) puts("Yes");
	else puts("No");
	
}

Measured memory_bytes: 256
#![allow(unused)]

use std::{cell, cmp, collections, convert, fmt, io, iter, ops, str};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($($args: tt)*) => { eprint!($($args)*) };
}

#[cfg(feature = "debug")]
macro_rules! debugln {
    ($($args: tt)*) => { eprintln!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($($args:tt)*) => {};
}

#[cfg(not(feature = "debug"))]
macro_rules! debugln {
    ($($args:tt)*) => {};
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn main() {
    let tasks = parse_vec::<i32>();

    let ans = tasks.iter().max().unwrap() - tasks.iter().min().unwrap();
    println!("{}", ans);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}

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

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if !buf.is_empty() {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn next_prime(x: i32) -> i32 {
    for i in (x + 1).. {
        if is_prime(i) {
            return i;
        }
    }

    panic!("attempt to add with overflow");
}

fn is_prime(x: i32) -> bool {
    let ceil = f64::from(x).sqrt().ceil() as i32;
    x == 2 || (2..(ceil + 1)).all(|i| x % i != 0)
}

fn bit_high(bits: u64, pos: u64) -> bool {
    bits & (1 << pos) != 0
}


Measured memory_bytes: 4352
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
l = []


if n >= m:
    print(0)
    exit()

for i in range(m - 1):
    l.append(x[i + 1] - x[i])

l = sorted(l)[::-1]

del l[0: n - 1]

print(sum(l))


Measured memory_bytes: 13968
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

#define SIZE(x) (int((x).size()))
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define repd(i,r,l) for (int i=(r); i>=(l); i--)
#define rept(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

#ifndef ONLINE_JUDGE
#define debug(x) { cerr<<#x<<" = "<<(x)<<endl; }
#else
#define debug(x) {}
#endif

#define maxn 100010

int op[maxn], used[maxn], cnt[maxn], u[maxn], com[maxn], lis[maxn], seq[maxn], where[maxn];

void lemon()
{
	int n,m,q; scanf("%d%d%d",&n,&m,&q);
	rep(i,1,q) scanf("%d",&op[i]);
	rep(i,1,q) cnt[op[i]]++;
	int s=0, zn=0;
	repd(i,q,1)
	{
		int ch=op[i];
		if (used[ch])
		{
			int which=lower_bound(com+1,com+q+2,-(where[ch]-1))-com;
			if (com[which]!=-(where[ch]-1)) continue;
			com[which]--;
		}
		else
		{
			used[ch]=1;
			s++; seq[s]=ch; where[ch]=s;
			com[1]--;
		}	
	}
	int place=-com[n];
	memset(used,0,sizeof used);
	rep(i,1,place) used[seq[i]]=1;
	int all=0;
	rep(i,1,m) if (!used[i]) { all++; lis[all]=i; }
	int cpos=1;
	rep(i,place+1,s)
	{
		if (seq[i]!=lis[cpos])
		{
			printf("No\n");
			return;
		}
		cpos++;
	}
	printf("Yes\n");
}

int main()
{
	ios::sync_with_stdio(true);
	#ifndef ONLINE_JUDGE
		//freopen("e.in","r",stdin);
	#endif
	lemon();
	return 0;
}



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

int main() {
    int i;
    double N,t;
    cin >> N;
    t = N / 1.08;

    if(t == (int)t)
        cout << t;
    else {
        i = (int)t+1;
        while(1) {
            if(int(i*1.08) == N) {
                cout << (int)i;
                break;
            }
            if(int(i*1.08) > N) {
                cout << ":(";
                break;
            }
            i++;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
  string A,B; cin>>A>>B;
  if(A[0]==B[2]&&A[1]==B[1]&&A[2]==B[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define MAX 1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int partition(int A[], int p, int r){
  int i, j;
  int x, t;
  x = A[r];
  i = p-1;
  for( j = p ; j < r ; j++ ){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(int A[], int p, int r){
  int q;
  if( p < r ){
    q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}


int solve(){
  int i, ans = 0;

  int V[MAX];
  for( i = 0 ; i < n ; i++ ){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(B, 0, n-1);
  for( i = 0 ; i < n ; i++ ) T[B[i]] = i;
  for( i = 0 ; i < n ; i++ ){
    if( V[i] ) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    while( 1 ){
      V[cur] = 1;
      an++;
      int v = A[cur];
      m = fmin(m, v);
      S += v;
      cur = T[v];
      if( V[cur] ) break;
    }
    ans += fmin(S+(an-2)*m, m+S+(an+1)*s);
  }

  return ans;
}

int main(){
  int i;
  scanf("%d",&n);
  s = VMAX;
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &A[i]);
    s = fmin(s, A[i]);
  }
  int ans = solve();
  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 2052
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
V vec1;
V vec2;
VV gragh;
ll n, u, v;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> u >> v;
    u--;
    v--;
    gragh.resize(n);
    rep(i, n - 1)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        gragh[a].push_back(b);
        gragh[b].push_back(a);
    }
    vec1.resize(n, -1);
    vec2.resize(n, -1);

    queue<ll> q;
    vec1[u] = 0;
    q.push(u);
    //  cout<<q.size()<<endl;
    while (!q.empty())
    {
        ll temp = q.front();
        q.pop();
        //  cout<<temp<<endl;
        rep(i, gragh[temp].size())
        {
            // cout<<"hello"<<endl;
            if (vec1[gragh[temp][i]] == -1)
            {
                //        cout<<"追って進む"<<temp<<" "<<gragh[temp][i]<<endl;
                vec1[gragh[temp][i]] = vec1[temp] + 1;
                q.push(gragh[temp][i]);
            }
        }
    }
    queue<ll> q1;
    vec2[v] = 0;
    q1.push(v);

    while (!q1.empty())
    {
        ll temp = q1.front();
        q1.pop();
        rep(i, gragh[temp].size())
        {
            if (vec2[gragh[temp][i]] == -1)
            {
                vec2[gragh[temp][i]] = vec2[temp] + 1;
                q1.push(gragh[temp][i]);
            }
        }
    }

    ll res = 0;
    rep(i, n)
    {    
        if(vec2[i]>vec1[i]){
            chmax(res,vec2[i]);
        }        
    }
    //  rep(i,n)cout<<vec1[i]<<" ";
    //  cout<<endl;
    //    rep(i,n)cout<<vec2[i]<<" ";
    //  cout<<endl;

    cout << res-1 << endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
//#define int long long

using namespace std;

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

    int t, K;
    cin >> t >> K;
    vector<int> heights;
    while (t--)
    {
        int a;
        cin >> a;
        heights.push_back(a);
    }
    int n = heights.size();
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(heights[1] - heights[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = INT_MAX;
        int k = 1;
        while (i - k >= 0 && k <= K)
        {
            dp[i] = min(dp[i], dp[i - k] + abs(heights[i - k] - heights[i]));
            k++;
        }
    }
    cout << dp[n - 1];
    return 0;
}

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

#define REP(i,n) for(int i = 0;i<(int)(n);i++)

template<int MOD>
class mod_int {
	unsigned x;
public:
	mod_int() : x(0) { }
	mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	mod_int &operator/=(mod_int that) { return *this *= that.inverse(); }

	mod_int operator+(mod_int that) const { return mod_int(*this) += that; }
	mod_int operator-(mod_int that) const { return mod_int(*this) -= that; }
	mod_int operator*(mod_int that) const { return mod_int(*this) *= that; }
	mod_int operator/(mod_int that) const { return mod_int(*this) /= that; }

	bool operator==(const mod_int& that) const { return x == that.x; }

	mod_int inverse() const {
		long long a = x, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		return mod_int(u);
	}
};

template<int MOD>
istream& operator >> (istream& is, mod_int<MOD>& val) {
	long long x;
	is >> x; val = x;
	return is;
}

template<int MOD>
ostream& operator << (ostream& os, const mod_int<MOD>& val) {
	os << val.get();
	return os;
}

const int mod = 1e9 + 7;
using mint = mod_int<mod>;

const int MAX = 3000;

mint p[MAX][MAX];
mint s[MAX + 1][MAX + 1];

vector<int> compress(vector<int>& v) {
	auto vs = v;
	sort(vs.begin(), vs.end());
	vs.erase(unique(vs.begin(), vs.end()), vs.end());
	for (auto& val : v) {
		val = lower_bound(vs.begin(), vs.end(), val) - vs.begin();
	}
	return vs;
}

int main()
{
	int N, Q;
	cin >> N >> Q;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	auto vs = compress(a);
	for (int i = 0; i < N; i++) {
		p[a[i]][i] = 1;
	}
	for (int j = 0; j < Q; j++) {
		int x, y;
		cin >> x >> y; x--; y--;
		for (int i = 0; i < N; i++) {
			p[i][x] = p[i][y] = (p[i][x] + p[i][y]) / 2;
		}
	}

	REP(i, N) REP(j, N) s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + p[i][j];

	auto b = a;
	sort(b.begin(), b.end());
	mint ans = 0;
	for (int i = 0; i < N; ) {
		int val = b[i], cnt = 0, x = i;
		while (i < N && b[i] == val) ++cnt, ++i;
		ans += cnt * x;
	}

	REP(i, N) REP(j, N) ans -= p[i][j] * (s[i][j] + s[i][j + 1]) / 2;

	REP(i, Q) ans *= 2;

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

Measured memory_bytes: 70784
#200
N = int(input())
A = list(map(int,input().split()))
judge = 1

for i in range(N):
    if A[i]%2 == 0:
        if A[i]%3 == 0 or A[i]%5 == 0:
            pass
        else:
            judge = 0
            
if judge == 1:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
	for(;;){
		int month;
		int day;
		int flg;
		int i;
		
		int past = 0;
		
		cin >> month;
		cin >> day;
		
		if(month == 0 && day == 0){
			break;
		}
		
		
	//	cout << month << day << endl;
		
		
		for(i = 0; i < month-1; i++){
			if(i == 1){
				past+=29;
			}
			else if(i == 0 || i == 2 || i == 4 || i == 6 || i == 7 || i == 9|| i == 11){
				past += 31;
			}
			else{
				past += 30;
			}
		}
		
		past += day-1;
		past%=7;
		
		switch(past){
			case 0:
				cout << "Thursday" << endl;
				break;
			case 1:
				cout << "Friday" << endl;
				break;
			case 2:
				cout << "Saturday" << endl;
				break;
			case 3:
				cout << "Sunday" << endl;
				break;
			case 4:
				cout << "Monday" << endl;
				break;
			case 5:
				cout << "Tuesday" << endl;
				break;
			case 6:
				cout << "Wednesday" << endl;
				break;
		}
	}
}

Measured memory_bytes: 0
/*
  AOJ 1131.cpp
  Time-stamp: <2012-11-27 23:48:45 nagana>
 */

#include <iostream>
#include <algorithm>

using namespace std;
int p,q,a;

// n:分割数 nowd:現在の分母 prod:今までの分母 total:今までの分子
int search(int n, int nowd, int prod, int total){
  int count = 0;
  
  for(int i = nowd; a >= prod * i; i++){
    // 通分して分子だけ見る
    int l,r;
    l = p * prod * i;
    r = total * i + prod;
    
    if(l == r *q){
      count++;
      continue;
    }
    if(l < r* q || n == 1){
      continue;
    }
    count += search(n - 1, i, prod*i, r);
    
  }
  return count;
}

      
      

int main(){
  int n;

  while(true){
    cin >> p >> q >> a >> n;
    if(!p & !q & !a & !n) break;

    cout << search(n, 1, 1, 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean chk = true;
        for(int i = 0; i < n; i++){
            int tmp = sc.nextInt();
            if(tmp % 2 == 0 && tmp % 3 != 0 && tmp % 5 != 0){
                chk = false;
                break;
            }
        }
        if(chk){
            System.out.println("APPROVED");
        }else{
            System.out.println("DENIED");
        }
    }
}

Measured memory_bytes: 24916
n = int(input()) 
a = [input() for _ in range(n)] 
b = [0,0,0,0] 
c = ["AC","WA","TLE","RE"]

for i in range(len(c)): 
    for k in range(n): 
        if a[k] == c[i]:
           b[i] += 1

for i in range(len(c)): 
    print(c[i]+" x "+str(b[i]))

Measured memory_bytes: 16008
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def primes_for(n):
   is_prime = [True] * (n + 1)
   is_prime[0] = False
   is_prime[1] = False
   for i in range(2, n + 1):
       for j in range(i * 2, n + 1, i):
           is_prime[j] = False
   return [i for i in range(n + 1) if is_prime[i]]

def totient(n):
  res = n
  for i in range(2, int(n**(1/2))+1):
    if n % i == 0:
      res = res / i*(i-1)
      while n % i == 0:
        n /= i
  if n != 1:
    res = res / n * (n-1)
  return res

def totient_list(n):
  euler = list(range(n+1))
  for i in range(2, n+1):
    if euler[i] == i:
      for j in range(i, n+1, i):
        euler[j] = euler[j] * (i-1) // i

  return euler

t = INT()
n = [INT() for _ in range(t)]

F = totient_list(10**6)
F[0] = 1
F = list(accumulate(F))

print("\n".join(map(str, [F[x] for x in n])))



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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<char>> g(h, vector<char>(w));
	rep(i, h) rep(j, w) cin >> g[i][j];
	
	const int dx[] = { 1,  0, -1,  0};
	const int dy[] = { 0,  1,  0, -1};
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			if(g[i][j] == '#'){
				bool success = false;
				for(int k = 0; k < 4; ++k){
					int nx = j + dx[k];
					int ny = i + dy[k];
					if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
					if(g[ny][nx] == '#'){
						success = true;
						break;
					}
				}
				if(!success){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 int n;
 cin >> n;
 double a[n],ans=0;
 for(int i=0;i<n;i++){
  cin >> a[i];
  ans+=1/a[i];
 }
 ans=1/ans;
 cout << fixed << setprecision(8) << ans;
  return 0;
}

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

int n,mn[30],a[30];
string s;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0;i<26;i++){
		mn[i]=INT_MAX;
	}
	while (n--){
		cin >> s;
		memset(a,0,sizeof(a));
		for (char &c : s){
			a[c-'a']++;
		}
		for (int i=0;i<26;i++){
			mn[i]=min(mn[i],a[i]);
		}
	}
	for (int i=0;i<26;i++){
		while (mn[i]--){
			cout << (char)('a'+i);
		}
	}
	cout << "\n";
}

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

typedef long long ll;

int main(){
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	set<ll> s;
	ll n;
	cin>>n;
	if(n==2){
		cout<<1;
		return 0;
	}
	s.insert(n);
	s.insert(n-1);
	for(ll i=2;i*i<=n;i++){
		ll temp=n;
		while(temp%i==0) temp/=i;
		if(temp%i==1) s.insert(i);
		if((n-1)%i==0) s.insert((n-1)/i);
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 256
// Equal Cut.cpp: 定义控制台应用程序的入口点。
// XG_Zepto, 7/3/2018. All rights reserved.

// #include "stdafx.h"
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define maxn 200101
using namespace std;
long long n,a[maxn],s[maxn],ans=0x7777777777777777;
long long gt(int l,int r){
	return s[r]-s[l];
}
int l,r,m;
bool movl(){
	if (l+1==m) return 0;
	long long t1=abs(gt(0,l)-gt(l,m));
	long long t2=abs(gt(0,l+1)-gt(l+1,m));
	return t2<=t1;
}
bool movr(){
	if (r+1==n) return 0;
	long long t1=abs(gt(m,r)-gt(r,n));
	long long t2=abs(gt(m,r+1)-gt(r+1,n));
	return t2<=t1;
}
void update(){
	long long t1=min(gt(0,l),min(gt(l,m),min(gt(m,r),gt(r,n))));
	long long t2=max(gt(0,l),max(gt(l,m),max(gt(m,r),gt(r,n))));
	ans=min(ans,t2-t1);
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;i++)
		cin>>a[i];
	for (int i=1;i<=n;i++)
		s[i]=s[i-1]+a[i];
	l=1,r=3,m=2;update();
    for (m=2;m<=n-2;m++){
		while(movl()) l++;
		while(movr()) r++;
		update();
	}
	cout<<ans<<endl;
//	system("PAUSE");
	return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var B = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var C = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(A);
            Array.Sort(B);
            Array.Sort(C);
            var answer = 0L;

            for (var i = 0; i < N; i++)
            {
                long ab = LowerBound(A, B[i]);
                long bc = N - UpperBound(C, B[i]);
                answer += ab * bc;
            }
            Console.WriteLine(answer);
        }

        public static int LowerBound<T>(IEnumerable<T> items, T key, Comparer<T> comparer = null)
        {
            return LowerBound(items.ToArray(), key, comparer);
        }

        public static int LowerBound<T>(T[] items, T key, Comparer<T> comparer = null)
        {
            comparer ??= Comparer<T>.Default;
            var left = 0;
            var right = items.Length - 1;
            while (left <= right)
            {
                var mid = left + (right - left) / 2;
                if (comparer.Compare(items[mid], key) == -1) left = mid + 1;
                else right = mid - 1;
            }

            return left;
        }

        public static int UpperBound<T>(IEnumerable<T> items, T key, Comparer<T> comparer = null)
        {
            return UpperBound(items.ToArray(), key, comparer);
        }

        public static int UpperBound<T>(T[] items, T key, Comparer<T> comparer = null)
        {
            comparer ??= Comparer<T>.Default;
            var left = 0;
            var right = items.Length - 1;
            while (left <= right)
            {
                var mid = left + (right - left) / 2;
                if (comparer.Compare(items[mid], key) <= 0) left = mid + 1;
                else right = mid - 1;
            }

            return left;
        }
    }
}


Measured memory_bytes: 46012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BigInteger a,b;
		final BigInteger max = new BigInteger("100000000000000000000000000000000000000000000000000000000000000000000000000000000");
		final BigInteger one = new BigInteger("1");
		
		final int loop;
		
		loop = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < loop; i++){
			
			a= new BigInteger(br.readLine());
			b= new BigInteger(br.readLine());
			
			if(a.divide(max).compareTo(one) >= 0 || a.divide(max).compareTo(one) >= 0){
				System.out.println("overflow");
				continue;
			}
			
			BigInteger sum = a.add(b);
			
			if(sum.divide(max).compareTo(one) >= 0){
				System.out.println("overflow");
				continue;
			}
			
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 9376
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var s = Console.ReadLine();
        int need = 8 - (15 - s.Length);

        if (s.Count(c => c == 'o') >= need)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 11220
function main(input) {
  const str = input.split("\n").join("");
  const arr = countChar(str);
  for (let i = "a".charCodeAt(0); i <= "z".charCodeAt(); i++) {
    console.log(`${String.fromCharCode(i)} : ${arr[i] || 0}`);
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function countChar(str) {
  const arr = [];
  str
    .toLowerCase()
    .split("")
    .forEach(c => {
      arr[c.charCodeAt(0)]
        ? (arr[c.charCodeAt(0)] += 1)
        : (arr[c.charCodeAt(0)] = 1);
    });
  return arr;
}



Measured memory_bytes: 15556
import java.util.Scanner;

public class Main {

    private static int sum(int aNum, int bNum, int cNum, int k) {
        int sum = 0;
        if (k <= aNum) {
            return k;
        } else {
            sum += aNum;
            k -= aNum;
        }

        if (k <= bNum) {
            return sum;
        } else {
            k -= bNum;
        }

        return sum + Math.min(k, cNum) * -1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int aNum = sc.nextInt(), bNum = sc.nextInt(), cNum = sc.nextInt(), k = sc.nextInt();

        System.out.println(sum(aNum, bNum, cNum, k));
        sc.close();
    }
}


Measured memory_bytes: 27076
#include<bits/stdc++.h>
using namespace std;
 
#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define pb push_back
#define fi first
#define se second
 
const int mod = 1e8;
const int maxn = 2e5 + 10;
const int maxm = 2e5 + 10;
const double PI = acos(-1.0);
const int inf = 1e9;
 
int n,k;
char s[maxn];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n >> k >> (s + 1);
    int ans = 0;
    rep(i,1,n){
        if(s[i] == s[i - 1]) ans++;
    }
    //cout << ans << endl;
    int i = 2; 
    while(i <= n && k){
        if(s[i] != s[i - 1]){
            int j = i;
            //cout << i << endl;
            while(j <= n && s[j] == s[i])j++;
            //cout << j << endl;
            if(s[j] == s[i] || j > n) ans++;
            else ans += 2;
            i = j + 1;
            k--;
        }
        else i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> connection(N);
  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    connection.at(a).push_back(b);
    connection.at(b).push_back(a);
  }
  vector<ll> way(N, -1);
  way.at(0) = 0;
  queue<ll> q;
  q.push(0);
  while (!q.empty()) {
    ll now = q.front();
    q.pop();
    for (ll i = 0; i < connection.at(now).size(); ++i) {
      ll next = connection.at(now).at(i);
      if (way.at(next) != -1) {
        continue;
      }
      way.at(next) = now;
      q.push(next);
    }
  }
  cout << "Yes" << "\n";
  for (ll i = 1; i < N; ++i) {
    cout << way.at(i) + 1 << "\n";
  }
}


Measured memory_bytes: 12920
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i=0,n,x,d,j,k,saidai=0,c=0,l;
    cin >> x;
    if(x==1)
    {
        cout << x << endl;
        return 0;
    }
    for(i=2;i<x;i++)
    {
        j=i;
        while(j<=x)
        {
           if(j*i>x)
           {
               break;
           }
           j=j*i;
           c++;
        }
        if(saidai<j && c>0)
        {
            saidai=j;
        }
        c=0;
    }
    cout << saidai << endl;
    return 0;
}


Measured memory_bytes: 3596
n = int(input())
a = list(map(int, input().split()))

flag = [False]*8
t = 0
for i in a:
  if i < 400: flag[0] = True
  elif i < 800: flag[1] = True
  elif i < 1200: flag[2] = True
  elif i < 1600: flag[3] = True
  elif i < 2000: flag[4] = True
  elif i < 2400: flag[5] = True
  elif i < 2800: flag[6] = True
  elif i < 3200: flag[7] = True
  elif 3200 <= i: t += 1
    
minNum = 0
p = flag.count(True)
if p > 0: minNum = p
elif p == 0 and t > 0:
  minNum = 1
  
maxNum = p + t

print(minNum,maxNum)

Measured memory_bytes: 9048
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    stack<int> stk;
    stk.push(0);
    int ret = 0;
    for(int i=0; i<n; ++i){
        while(stk.top() > a[i])
            stk.pop();
        if(stk.top() != a[i])
            ++ ret;
        stk.push(a[i]);
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 2584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char c){
	vector<string> vs;
	string w;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == c){
			vs.push_back(w);
			w = "";
		}else{
			w += s[i];
		}
	}
	if(w.size() > 0){ vs.push_back(w); }
	return vs;
}

string join(const vector<string> &vs, char c){
	string s;
	for(int i = 0; i < vs.size(); ++i){ s += c + vs[i]; }
	return s;
}

string normalize(const string &s, const vector<string> &fs){
	vector<string> vs = split(s.substr(1), '/');
	vector<string> nvs;
	for(int i = 0; i < vs.size(); ++i){
		if(vs[i] == "."){
			// nothing to do
		}else if(vs[i] == ".."){
			if(nvs.empty()){ return "#"; }
			nvs.pop_back();
		}else{
			nvs.push_back(vs[i]);
			if(i + 1 == vs.size()){ continue; }
			string t = join(nvs, '/');
			vector<string>::const_iterator it =
				lower_bound(fs.begin(), fs.end(), t + "/");
			if(it == fs.end() || it->substr(0, t.size() + 1) != t + "/"){
				return "#";
			}
		}
	}
	string t = join(nvs, '/');;
	if(s[s.size() - 1] != '/' && binary_search(fs.begin(), fs.end(), t)){
		return t;
	}else if(binary_search(fs.begin(), fs.end(), t + "/index.html")){
		return t + "/index.html";
	}else{
		return "#";
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		vector<string> fs(n);
		for(int i = 0; i < n; ++i){ cin >> fs[i]; }
		sort(fs.begin(), fs.end());
		for(int i = 0; i < m; ++i){
			string a, b;
			cin >> a >> b;
			const string na = normalize(a, fs);
			const string nb = normalize(b, fs);
			if(na == "#" || nb == "#"){
				cout << "not found" << endl;
			}else if(na == nb){
				cout << "yes" << endl;
			}else{
				cout << "no" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
using namespace std;
using llong = long long;

llong a, b, c, k;

int main() {
    cin >> a >> b >> c >> k;

    if (a + b < k) {
        cout << a - (k - (a + b)) << endl;
    }
    else {
        cout << min(a, k) << endl;
    }
}


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

const int Max = 2e5+3;
vector<int> adj[Max];
bool visited[Max];
int cntA[Max] = {0}, cntB[Max] = {0};
string s;
bool seenA, seenB;

void dfs(int node) {
    if(s[node-1] == 'A') {
        seenA = true;
    } else {
        seenB = true;
    }
    visited[node] = true;
    for(int to : adj[node]) {
        if(visited[to]) continue;
        dfs(to);
    }    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    fill(visited, visited+n+2, false);
    cin >> s;
    int u, v;
    vector<pair<int, int> > edges(m);
    for(int i = 0; i < m; ++i) {
        cin >> u >> v;
        edges[i] = {u,v};
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    queue<int> q;
    for(int i = 1; i <= n; ++i) {
        for(int to : adj[i]) {
            if(s[to-1] == 'A') {
                cntA[i]++;
            } else {
                cntB[i]++;
            }
        }
        if(cntA[i] == 0 || cntB[i] == 0) {
            q.push(i);
            visited[i] = true;
        }
    }
    while(!q.empty()) {
        int node = q.front();
        q.pop();
        for(int to : adj[node]) {
            if(visited[to]) continue;
            if(s[node-1] == 'A') {
                cntA[to]--;
            } else {
                cntB[to]--;
            }
            if(cntA[to] == 0 || cntB[to] == 0) {
                q.push(to);
                visited[to] = true;
            }
        }
    }
    /*
    for(int i = 1; i <= n; ++i) {
        if(!visited[i]) cout << "here: " << i << '\n';
    }*/
    for(int i = 0; i < m; ++i) {
        u = edges[i].first;
        v = edges[i].second;
        if(!visited[u] && !visited[v] && s[v-1] != s[u-1]) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    /*
    for(int i = 1; i <= n; ++i) {
        if(visited[i]) continue;
        seenA = seenB = false;
        dfs(i);
        if(!seenA || !seenB) continue;
        
    }*/
    return 0;
}










































Measured memory_bytes: 14032
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a=new int[100001];
		int[] b=new int[100001];
		a[1]=0;
		b[0]=b[1]=-1;
		for(int i = 2; i<100001; i++){
			a[i]+=a[i-1];
			if(b[i]!=-1){
				int k=i;
				k+=i;
				while(k<100001){
					b[k]=-1;
					k+=i;
				}
				if(b[(i+1)/2]!=-1){
					a[i]++;
				}
			}
		}
		int q = sc.nextInt();
		int[] ans=new int[q];
		for(int i = 0; i<q; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();
			ans[i]=a[r]-a[l-1];
		}
		for(int i = 0; i<q; i++){
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 66916
#include <stdio.h>

int main(void){
    int a[]={1,5,10,50,100,500},b[5],sum = 0,i,x;
    for(i = 0;i <= 5;i++)
        scanf("%d",&b[i]);
    for(i = 0;i <= 5;i++)
        sum += a[i] * b[i];
    if(sum >=1000)
        x = 1;
    else
        x = 0;
    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 1836
<?php

	$data = explode(" ", trim(fgets(STDIN)));
	$a = $data[0];
	$b = $data[1];
	$c = $data[2];
	$ans = 0;
	$ans += $b;
	if($c>$b){
	    $ans += $b;
	    $c -= $b;
	} else {
	    $ans += $c;
	    $c = 0;
	}
	
	if($c<$a) $ans += $c;
	else{
	    $ans += $a;
	    $c -= $a;
	    if($c>0) $ans++;
	}
	
	echo $ans;
?>

Measured memory_bytes: 4728
# include<iostream>
# include<math.h>
using namespace std;

int main(void)
{
	int a[10];
	int n;
	while(cin >> n && n != 0)
	{
		int max, min, i;
		for(i = 0; i < 10; ++i)
			a[i] = 0;
		for(i = 0; i < n; ++i)
		{
			int q;
			cin >> q;
			if(q <= 399)
				a[0]++;
			else if(q <= 799)
				a[1]++;
			else if(q <= 1199)
				a[2]++;
			else if(q <= 1599)
				a[3]++;
			else if(q <= 1999)
				a[4]++;
			else if(q <= 2399)
				a[5]++;
			else if(q <= 2799)
				a[6]++;
			else if(q <= 3199)
				a[7]++;
			else
				a[8]++;
		}
		int sum = 0;
		for(i = 0; i <= 7; ++i)
		{
			if(a[i] > 0)
				sum++;
		}
		max = sum + a[8];
		min = sum;
		if(sum == 0)
		{
			min = 1;
			max = a[8];
		}
		cout << min << " " << max << endl;
	}
	
	return 0;
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

int main()
{
    ll a;
    cin >> a;
    OUT0(a+a*a+a*a*a);
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    sort(all(a));
    
    int b,c;
    b = a.back();
    int d = 1000000000;
    if(b%2 == 0){
        int bb = b/2;
        rep(i,n-1){
            if(abs(a[i]-bb) < d){
                d = abs(a[i]-bb);
                c = a[i];
            }
        }
    }else{
        int bb = b/2;
        rep(i,n-1){
            if(abs(a[i]-bb) < d){
                d = abs(a[i]-bb);
                c = a[i];
            }
        }
        bb = b/2 + 1;
        rep(i,n-1){
            if(abs(a[i]-bb) < d){
                d = abs(a[i]-bb);
                c = a[i];
            }
        }
    }
    
    cout << b << " " << c << endl;
    
    return 0;
}



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

#include <climits>
#include <cmath>
#include <cstring>

#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	string s,t;
	cin >> s >> t;

	int n = s.size();
	int m = t.size();
	string ans = "~";
	for(int i=0 ; i<=n-m ; i++)
	{
		string temp = s;
		bool ok = true;
		for(int j=0 ; j<t.size() ; j++)
		{
			if(temp[i+j] != '?' && temp[i+j] != t[j])
			{
				ok=false;
				break;
			}
			temp[i+j] = t[j];
		}

		if(ok)
		{
		    replace(temp.begin() , temp.end() , '?' , 'a');
			ans = min(ans , temp);
		}
	}
	if(ans == "~")
		cout << "UNRESTORABLE";
	else
		cout << ans;	
	return 0;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())
N = len(S)

for i in range(N):
    R = S.copy()

    for j in range(N):
        if j == N-1:
            S[0] = R[N-1]
        else:
            S[j+1] = R[j]

    if T == S:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 3064
using System;

namespace AOJ.Volume5
{
    public class Score
    {
        public static int Main()
        {
            var input = Console.ReadLine().Split(' ');
            int s = 0;
            for(int i = 0; i < 4; i++)
            {
                s += int.Parse(input[i]);
            }

            input = Console.ReadLine().Split(' ');
            int t = 0;
            for(int i = 0; i < 4; i++)
            {
                t += int.Parse(input[i]);
            }

            Console.WriteLine(Math.Max(s, t));
            return 0;
        }
    }
}

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.length();
	if (s[0] == '0' || s[n-1] == '1') {
		cout << -1 << endl;
		return 0;
	}
	vector<int> a;
	for (int i = 1; i <= n-i; ++ i) {
		if (s[i-1] != s[n-i-1]) {
			cout << -1 << endl;
			return 0;
		}
		if (s[i-1] == '1') {
			a.push_back(i);
		}
	}
	//for (auto x : a) cerr << x << endl;
	int p = 1, q = 1;
	for (int x : a) {
		int w = q;
		cout << q << " " << ++ p << endl;
		q = p;
		while (p <= x) {
			cout << w << " " << ++ p << endl;
		}
	}
	while (p < n) {
		cout << q << " " << ++ p << endl;
	}
}


Measured memory_bytes: 1916