akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    while ( s.length() ) {
        if ( s.length() >= 5 && s.substr( s.length() - 5 , 5 ) == "dream" ) {
            for (int i = 0 ; i < 5 ; i++) s.pop_back();
        }
        else if ( s.length() >= 7 && s.substr( s.length() - 7 , 7 ) == "dreamer" ) {
            for (int i = 0 ; i < 7 ; i++) s.pop_back();
        }
        else if ( s.length() >= 5 && s.substr( s.length() - 5 , 5 ) == "erase" ) {
            for (int i = 0 ; i < 5 ; i++) s.pop_back();
        }
        else if ( s.length() >= 6 && s.substr( s.length() - 6 , 6 ) == "eraser" ) {
            for (int i = 0 ; i < 6 ; i++) s.pop_back();
        }
        else {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}

Measured memory_bytes: 512
///
// File:  alds1_3_b.cpp
// Author: ymiyamoto
//
// Created on Fri Oct  6 01:08:23 2017
//

#include <cstdint>
#include <iostream>

using namespace std;
#define SIZE 200000
static pair<string, int32_t> que[SIZE];
static uint32_t top;
static uint32_t bottom;

static void push(pair<string, int32_t> val)
{
  que[bottom] = val;
  bottom++;
  bottom %= SIZE;
}

static pair<string, int32_t> pop()
{
  pair<string, int32_t> val = que[top];
  top++;
  top %= SIZE;
  return val;
}

static bool empty()
{
  return top == bottom;
}

int32_t main()
{
  int32_t n, q;
  cin >> n >> q;
  for (int32_t i = 0; i < n; i++) {
    string str;
    int32_t val;
    cin >> str >> val;
    push({str, val});
  }

  uint64_t current_time = 0;
  while (!empty()) {
    auto val = pop();
    if (val.second - q <= 0) {
      current_time += val.second;
      cout << val.first << " " << current_time << endl;
    } else {
      current_time += q;
      push({val.first, val.second - q});
    }
  }

  return 0;
}

Measured memory_bytes: 8488
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int A, B;

	cin >> A >> B;

	if (A <= 2 * B) {
		cout << "0" << endl;
	} else {
		cout << A - 2 * B << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <utility>
#include <cstdio>
#include <queue>
#define MOD 1000000007
typedef long long ll; 
ll ds[100005], dt[100005]; 
int dps[100005], dpt[100005]; 
int lst[100005], to[400005], pre[400005], w[400005], tot; 
std::priority_queue<std::pair<ll, int> > que; 
inline void add_edge(int u, int v, int _w)
{
	to[tot] = v; 
	pre[tot] = lst[u];
	w[tot] = _w; 
	lst[u] = tot++; 
}
void work(int n, int s, ll *dis, int *dp)
{
	memset(dis, 0x3f, n << 3); 
	dis[s] = 0; 
	dp[s] = 1; 
	que.push({0, s}); 
	while (!que.empty())
	{
		ll d = -que.top().first;
		int u = que.top().second; 
		que.pop(); 
		if (dis[u] != d)
			continue; 
		for (int i = lst[u]; ~i; i = pre[i])
		{
			int v = to[i]; 
			if (dis[v] > dis[u] + w[i])
			{
				dis[v] = dis[u] + w[i]; 
				dp[v] = 0; 
				que.push({-dis[v], v}); 
			}
			if (dis[v] == dis[u] + w[i])
				(dp[v] += dp[u]) %= MOD; 
		}
	}
}
int main()
{
	// freopen("ARC090-E.in", "r", stdin); 
	memset(lst, -1, sizeof(lst)); 
	int n, m, s, t; 
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for (int i = 0; i < m; i++)
	{
		int u, v, _w; 
		scanf("%d%d%d", &u, &v, &_w);
		add_edge(--u, --v, _w); 
		add_edge(v, u, _w);
	}
	work(n, --s, ds, dps); 
	work(n, --t, dt, dpt); 
	ll ans = (ll)dps[t] * dps[t] % MOD; 
	// printf("%lld\n", ans);
	for (int i = 0; i < n; i++)
	{
		if (ds[i] + dt[i] == ds[t] && ds[i] == dt[i])
			(ans -= (ll)dps[i] * dps[i] % MOD * dpt[i] % MOD * dpt[i]) %= MOD; 
		for (int k = lst[i]; ~k; k = pre[k])
		{
			int j = to[k];
			if (ds[i] + dt[j] + w[k] == ds[t] && ds[i] * 2 < ds[t] && dt[j] * 2 < ds[t])
				(ans -= (ll)dps[i] * dps[i] % MOD * dpt[j] % MOD * dpt[j]) %= MOD; 
		}
	}
	printf("%lld\n", (ans + MOD) % MOD);
	return 0; 
}


Measured memory_bytes: 9332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		if(90 <= N && N <= 99 || (N+1)%10 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		sc.close();
	}

}


Measured memory_bytes: 21844
n=int(input())
a=list(map(int,input().split()))
a1=0
a2=0
a3=0
a4=0
a5=0
a6=0
a7=0
a8=0
wild=0
for i in range(n):
    if 0<=a[i]<=399:
        a1+=1
    elif 400<=a[i]<=799:
        a2+=1
    elif 800<=a[i]<=1199:
        a3+=1
    elif 1200<=a[i]<=1599:
        a4+=1
    elif 1600<=a[i]<=1999:
        a5+=1
    elif 2000<=a[i]<=2399:
        a6+=1
    elif 2400<=a[i]<=2799:
        a7+=1
    elif 2800<=a[i]<=3199:
        a8+=1
    else:
        wild+=1
ans=0
r=[]
r.append(a1)
r.append(a2)
r.append(a3)
r.append(a4)
r.append(a5)
r.append(a6)
r.append(a7)
r.append(a8)
for i in range(8):
    if r[i]!=0:
        ans+=1
print(max(ans,1),ans+wild)

Measured memory_bytes: 3064
# include <bits/stdc++.h>
#define INF 9223372036854775807
using namespace std;

int main(){

  long int N;
  cin >> N;
  long int min_a = INF;
  for(int i=0; i < 5; i++){
    long int a;
    cin >> a;
    min_a = min(min_a, a);
  }
  // cout << min_a << endl;
  long int ans;
  ans = 4 + ceil((long double) N / (long double) min_a);
  cout << ans << endl;

}


Measured memory_bytes: 512
n,a=map(int,input().split())
x=list(map(int,input().split()))
for i in range(len(x)):
    x[i]-=a
li=[[0]*5001 for i in range(n+1)]
for i in range(n):
    li[i+1][2500+x[i]]+=1
    for j in range(5001):
        if li[i][j]>=1:
            li[i+1][j+x[i]]+=li[i][j]
            li[i+1][j]+=li[i][j]
    # print(li[i+1][2490:2510])
print(li[n][2500])

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

pair<int, int> solve(string s)
{
  int len = s.length();
  if(len == 1) return make_pair(-1, -1);
  if(len == 2)
   if(s[0] == s[1])
    return make_pair(1, 2);
   else
    return make_pair(-1, -1);

  for(int i=0; i<=len-3; i++)
   if(s[i] == s[i+1] || s[i] == s[i+2])
    return make_pair(i+1, i+3);
  return make_pair(-1, -1);
}

int main()
{
  string s;
  cin>>s;
  pair<int, int> r = solve(s);
  cout<<r.first<<" "<<r.second;
  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], rui[500000], dp[5000];
str S, T; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> a >> b;

	if (a % b == 0)cout << a / b << endl;
	else cout << a / b + 1 << endl;


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll k,n;
    cin>>k>>n;
    ll arr[n+5]={0};
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll dis=arr[0]-arr[n-1]+k;
    for(int i=0;i<n-1;i++)
    {
        ll x=abs(arr[i+1]-arr[i]);
        dis=max(dis,x);
    }
    cout<<k-dis<<endl;
}


Measured memory_bytes: 5184
import math

def dist(XY, i, j):
  return math.sqrt((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2)

N = int(input())
XY = [[0, 0] for _ in range(N)]
for i in range(N):
  XY[i] = [int(x) for x in input().split()]
D = [[0.0 for _ in range(N)] for _ in range(N)]
E = 0.0
for i in range(N):
  for j in range(N):
    E += dist(XY, i, j) / float(N)
print(E)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   cin >> n;
   vector<pair<int,int>> v(n);
   rep(i,n){
      int x,y;
      cin >> x >> y;
      v[i] = {x,y};
   }
   vector<int> per(n);
   rep(i,n){
      per[i] = i;
   }
   double ans = 0.0;
   int fact = 0;
   do{
      for (int i = 0;i < n-1;i++){
         ans +=  sqrt((v[per[i]].first-v[per[i+1]].first)*double(v[per[i]].first-v[per[i+1]].first) + 
                      (v[per[i]].second-v[per[i+1]].second)*double(v[per[i]].second-v[per[i+1]].second));
                      
      }
      fact++;

   }while(next_permutation(per.begin(),per.end()));
   printf("%.10f\n",ans/double(fact)); 


   return 0;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let  x:i64 = sc.read();
    let mut ans:i64 = x-1;
    for i in 2..(1000001 as usize){
        let j = i as i64;
        if x >= j*j{
            if x%j == 0{
                if ans > j-1 + x/j-1{
                    ans = j-1 + x/j-1;
                }
            }
        }else{
            break;
        }
    }
    println!("{}", ans);
    
}



pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




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

#define rep(i,x) for(int i=0;i<x;i++)
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> elements(m, vector<int>(2));
    rep(i, m) cin >> elements[i][0] >> elements[i][1];
    vector<int> order(n);
    rep(i, n) order[i] = i + 1;
    int ans = 0;
    do{
        if (order[0] != 1) break;
        bool allok = true;
        rep(i, n - 1){
            vector<int> ab(2);
            ab[0] = order[i]; ab[1] = order[i+1];
            sort(ab.begin(), ab.end());
            bool ok = false;
            for (vector<int> element : elements){
                if (ab == element) ok = true;
            }
            if (!ok){
                allok = false;
                break;
            }
        }
        if (allok) ans++;
    }while (next_permutation(order.begin(), order.end()));
    cout << ans << endl;
}


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

using namespace std;
int a[100050];
int dp[100050];
const int INF =1<<30;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		dp[i]=INF;
	}
	
	dp[0]=0;
	for(int i=0;i<n-1;i++){
		if(i==n-2)	dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
		else{
			dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
			dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));	
		}
	}
	cout<<dp[n-1];
	
	return 0;
}


Measured memory_bytes: 1024
w = int(input())
arr = [i+1 for i in range(w)]
for i in range(int(input())):
    s = input().split(",")
    a,b = int(s[0]), int(s[1])
    temp = arr[a-1]
    arr[a-1] = arr[b-1]
    arr[b-1] = temp
for i in range(w):
    print(arr[i])

Measured memory_bytes: 7732
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define puts(x) cout << x << "\n"
using namespace std;
signed main() {
	int n, k, s; cin >> n >> k >> s;
	for0(i, n) {
		if (i)cout << ' ';
		if (i < k)cout << s;
		else cout << (s + 1) % 1000000000;
	}puts("");
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll inf=1ll<<54;
int n,m,a,b;
ll s[maxn],q[maxn],f[maxn],ans=inf;
inline int read(){
    int x=0,f=1;char ch=getchar();
    for(;ch>'9'||ch<'0';f=ch=='-'?-1:1,ch=getchar());
    for(;ch<='9'&&ch>='0';x=x*10+ch-48,ch=getchar());
    return x*f;
}
#define mid (l+r>>1)
#define ls (root<<1)
#define rs (root<<1|1)
ll t[maxn<<2][2];
void build(int root,int l,int r,int id){
    t[root][id]=inf;
    if(l==r)return;
    build(ls,l,mid,id);build(rs,mid+1,r,id);
}
void update(int root,int l,int r,int k,ll v,int id){
    if(l==r){t[root][id]=v;return;}
    if(k<=mid)update(ls,l,mid,k,v,id);
    else update(rs,mid+1,r,k,v,id);
    t[root][id]=min(t[ls][id],t[rs][id]);
}
ll query(int root,int l,int r,int a,int b,int id){
    if(l==a&&r==b)return t[root][id];
    if(b<=mid)return query(ls,l,mid,a,b,id);
    else if(a>mid)return query(rs,mid+1,r,a,b,id);
	return min(query(ls,l,mid,a,mid,id),query(rs,mid+1,r,mid+1,b,id));
}
void solve(int a,int b){
	f[1]=abs(a-q[1]);build(1,1,m,0);build(1,1,m,1);
    update(1,1,m,b,f[1]-b-s[1],0);
    update(1,1,m,b,f[1]+b-s[1],1);
    for(int i=2;i<=n;i++){
        f[i]=min(query(1,1,m,1,q[i],0)+q[i],
		query(1,1,m,q[i],m,1)-q[i])+s[i-1];
        update(1,1,m,q[i-1],f[i]-q[i-1]-s[i],0);
        update(1,1,m,q[i-1],f[i]+q[i-1]-s[i],1);
    }
    for(int i=1;i<=n;i++)ans=min(ans,f[i]+s[n]-s[i]);
}
int main(){
    m=read();n=read();a=read();b=read();
    for(int i=1;i<=n;i++)q[i]=read();
    for(int i=2;i<=n;i++)s[i]=s[i-1]+abs(q[i]-q[i-1]);
    solve(a,b);solve(b,a);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 15360
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int t[105], val[105], dp[1<<16][105];
signed main(void)
{
  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    REP(i, n) {
      int m, l;
      cin >> m >> l;
      val[i] = l;
      t[i] = 0;
      REP(j, m) {
        int s, e;
        cin >> s >> e;
        FOR(k, s, e) t[i] |= 1<<(k-6);
      }
    }

    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    REP(i, n) {
      REP(j, 1<<16) {
        if(dp[j][i] < 0) continue;
        // cout << i << " " << bitset<16>(j) << endl;
        dp[j][i+1] = max(dp[j][i+1], dp[j][i]);
        // t[i] ??? j ???????????????????????????
        bool flag = true;
        REP(k, 16) {
          if(((t[i]>>k)&1) && ((j>>k)&1)) {
            flag = false;
            // cout << "false" << k << endl;
          }
        }
        // cout << flag << endl;
        if(flag) {
          // cout << bitset<16>(j|t[i]) << " " << dp[j|t[i]][i+1] << " " << dp[j][i] + val[i] << endl;
          dp[j|t[i]][i+1] = max(dp[j|t[i]][i+1], dp[j][i] + val[i]);
        }
      }
    }

    ll ret = 0;
    REP(i, 1<<16) chmax(ret, dp[i][n]);
    cout << ret << endl;
  }

  return 0;
}

Measured memory_bytes: 56756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// O(HW)
int H,W;
char maze[1010][1010];
int d[1010][1010];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void bfs(){
    queue<pair<int,int>> que;
    rep(i,H){
        rep(j,W){
            d[i][j]=INF;
        }
    }
    que.push(make_pair(0,0)); // (0,0)スタート
    d[0][0]=0;
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && maze[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(make_pair(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
}

int main() {
    cin>>H>>W;
    int ans=0;
    rep(i,H){
        rep(j,W){
            cin>>maze[i][j];
            if(maze[i][j]=='.') ans++;
        }
    }

    bfs();
    if(d[H-1][W-1]==INF){
        cout<<-1<<endl;
        return 0;
    }

    cout<<ans-(d[H-1][W-1]+1)<<endl;
}



Measured memory_bytes: 2432
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int ans[200005];

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int x;
	for(int i=0;i<n-1;i++)
	{
		cin>>x;
		ans[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4424
#include <iostream>
#include <math.h>
#include<queue>
#include<vector>

using namespace std;
int main() {

	int n,m;
	cin>>n>>m;
	vector<int> cnt(n,0);
	vector<vector<int> > g0(n);
	//vector<vector<int> > g1(n);
	//vector<vector<int> > g2(n);
	for(int i=0;i<m;i++){
	  int u,v;
	  cin>>u>>v;
	  u--;
	  v--;
	  g0[u].push_back(v);
	 }
	 int dist[n][3];
	 for(int i=0;i<n;i++){
	   for(int j=0;j<3;j++){
	     dist[i][j]=1e9;
	   }
	  }
	  queue<pair<int,int> > Q;
	  int s,t;
	  cin>>s>>t;
	  s--,t--;
	  Q.push({s,0});
	  dist[s][0]=0;
	  while(!Q.empty()){
	    int a=Q.front().first;
	    int b=Q.front().second;
	    Q.pop();
	    
	    for(int i=0;i<g0[a].size();i++){
	      if(dist[g0[a][i]][(b+1)%3]==1e9)Q.push({g0[a][i],(b+1)%3});
	      else continue;
	      dist[g0[a][i]][(b+1)%3]=dist[a][b]+1;
	     }
	   }
	   if(dist[t][0]==1e9)cout<<-1<<endl;
	   else cout<<dist[t][0]/3<<endl;
}

Measured memory_bytes: 7296
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

void dfs(long par, long now, long& res, vector<vector<long>>& tree, long K) {

    //それぞれのノードに対して色は(K - 2 P 子の数)通り

	long canuse = K - 2;

	if (now == 0) canuse++;

	for (long e : tree[now]) {
		if (e == par) continue;
		res *= canuse;
		if (res == 0) return;
		canuse--;
		res %= mod;
	}


	for (long e : tree[now]) {
		if (e == par) continue;

		dfs(now, e, res, tree, K);
	}

}

int main() {

	long N, K; cin >> N >> K;
	long res = K;//根の配色

	vector<vector<long>> tree(N);

	for (int i = 0; i < N - 1; i++) {
		long a, b; cin >> a >> b;
		--a; --b;

		tree[a].push_back(b);
		tree[b].push_back(a);

	}

	dfs(-1, 0,res, tree, K);

	res %= mod;
	cout << res << endl;

}

Measured memory_bytes: 11520
#include <stdio.h>
#define N 1000000000

typedef struct {
  char suit;
  int value;
}card;

card l[50002], r[50002];

void merge(card a[], int n, int left, int mid, int right)
{
  int i, j, k, n1, n2;

  n1 = mid - left;
  n2 = right - mid;
  for (i = 0; i < n1; i++)
    l[i] = a[left+i];
  for (i = 0; i < n2; i++)
    r[i] = a[mid+i];
  l[n1].value = r[n2].value = N;
  i = j = 0;
  for (k = left; k < right; k++){
    if (l[i].value <= r[j].value)
      a[k] = l[i++];
    else
      a[k] = r[j++];
  }
}

void mergesort(card a[], int n, int left, int right)
{
  int mid;

  if (left+1 < right){
    mid = (left+right)/2;
    mergesort(a,n,left,mid);
    mergesort(a,n,mid,right);
    merge(a,n,left,mid,right);
  }
}

int partition(card a[], int n, int p, int r)
{
  int i, j;
  card x, y;

  y = a[r];
  i = p - 1;
  for (j = p; j < r; j++)
    if (a[j].value <= y.value){
      i++;
      x = a[i];
      a[i] = a[j];
      a[j] = x;
    }
  x = a[i+1];
  a[i+1] = a[r];
  a[r] = x;
  
  return i+1;
}

void quicksort(card a[], int n, int p, int r)
{
  int q;

  if (p < r){
    q = partition(a,n,p,r);
    quicksort(a,n,p,q-1);
    quicksort(a,n,q+1,r);
  }
}

int main()
{
  int n, i, x, stable = 0;
  card a[100000], b[100000];
  char s[10];

  scanf("%d",&n);
  for (i = 0; i < n; i++){
    scanf("%s%d",s,&x);
    a[i].suit = b[i].suit = s[0];
    a[i].value = b[i].value = x;
  }
  mergesort(a,n,0,n);
  quicksort(b,n,0,n-1);
  for (i = 0; i < n; i++)
    if (a[i].suit != b[i].suit)
      stable++;
  if (stable == 0)
    printf("Stable\n");
  else
    printf("Not stable\n");
  for (i = 0; i < n; i++)
    printf("%c %d\n",b[i].suit,b[i].value);

  return 0;
}



Measured memory_bytes: 4040
s = input()[::-1]
t = input()[::-1]

res = 'UNRESTORABLE'
for i in range(len(s)-len(t)+1):
    for ss, tt in zip(s[i:i+len(t)], t):
        if ss == '?' or ss == tt:
            continue
        break
    else:
        res = ((s[:i] + t + s[i+len(t):])[::-1]).replace('?', 'a')
        break

print(res)


Measured memory_bytes: 3060
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


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

    N = ii()
    ans = 0
    for x in range(1, N + 1):
        n = N // x  # Nのうちにxがいくつ含まれるか（等差数列の項数）
        ans += (n * (2 * x + (n - 1) * x)) // 2  # 初項と公差がxでn項の等差数列の和
    print(ans)


if __name__ == '__main__':
    main()


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
 
int main() {
  ll h,w,a,b ; 
  cin>>h>>w>>a>>b;
  
  rep(i,b){
    rep(j,a) cout<<0;
    rep(j,w-a) cout<<1;
    cout<<endl;
  }
  rep(i,h-b){
    rep(j,a) cout<<1;
    rep(j,w-a) cout<<0;
    cout<<endl;
  }
  
}
  



Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MOD = 1e9 + 7;
const int MAX = 1e5;
const int MV = 1e5;
const int INF = 2e9;
ll MA = -INF , MI = INF , ANS;

int n;
map<int,int> amo;
vector<ll> vec;
ll vc;

int32_t main()
{
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	cin >> n;

	for(int i=0 ; i<n ; i++)
	{
		ll x;
		cin >> x;
		amo[x]++;
		if( amo[x] == 2 )
			vec.pb(x);
		else if( amo[x] == 4 )
			vc = max( vc , x );
	}

	sort( vec.begin() , vec.end() );

	if( vec.size() < 2 && vc == 0 )
		return cout << 0 , 0;

	int m = vec.size();
	MA = max( MA , vec[m-1] * vec[m-2] );

	MA = max( MA , vc * vc );

	cout << MA << "\n";


	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, A, B, C, D; //A本でB円、C本でD円
    cin >> N >> A >> B >> C >> D;
    //X
    int m, money1;
    for(int i = 1;; i++){
        m = A * i;
        if(m >= N){
            //cout << B * i << endl;
            money1 = B * i;
            break;
        }
        
    }
    
    //Y
    int n, money2;
    for(int i = 1;; i++){
        n = C * i;
        if(n >= N){
            //cout << D * i << endl;
            money2 = D * i;
            break;
        }
    }
    if(money1 > money2) cout << money2 << endl;
    else cout << money1 << endl;
}



Measured memory_bytes: 3084
a,b = map(int, input().split())
if a==0 or b==0:
    print('Zero')
elif a<0 and b>0:
    print('Zero')
elif a>0 and b<0:
    print('Zero')    
elif a>0 and b>0:
    print('Positive')
elif a<0 and b<0:
    if abs(a-b)%2==0:
        print('Negative')
    else:
        print('Positive')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;



int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    int mx = a.back();
    int t = a[0];
    int t_diff = min(abs(mx/2 - a[0]), abs(mx/2+(mx%2) - a[0]));;
    srep(i, n-1, 1) {
        int diff = min(abs(mx/2 - a[i]), abs(mx/2+(mx%2) - a[i]));
        if (diff < t_diff) {
            t = a[i];
            t_diff = diff;
        }
    }

    cout << mx << " " << t << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>

int main()
{
    int a, b, c, d, n;
    scanf("%d", &n);

    a = n / 1000;
    n -= 1000 * a;

    b = n / 100;
    n -= 100 * b;

    c = n / 10;
    n -= 10 * c;

    d = n;

    if (a + b + c + d == 7) printf("%d+%d+%d+%d=7", a, b, c, d);
    else if (a + b + c - d == 7) printf("%d+%d+%d-%d=7", a, b, c, d);
    else if (a + b - c + d == 7) printf("%d+%d-%d+%d=7", a, b, c, d);
    else if (a + b - c - d == 7) printf("%d+%d-%d-%d=7", a, b, c, d);
    else if (a - b + c - d == 7) printf("%d-%d+%d-%d=7", a, b, c, d);
    else if (a - b - c + d == 7) printf("%d-%d-%d+%d=7", a, b, c, d);
    else if (a - b - c - d == 7) printf("%d-%d-%d-%d=7", a, b, c, d);
    else if (a - b + c + d == 7) printf("%d-%d+%d+%d=7", a, b, c, d);
}

Measured memory_bytes: 128
s = gets.chomp
q = gets.to_i
q.times do |i|
    t = gets.split
    order = t[0]
    a = t[1].to_i
    b = t[2].to_i
    case order
    when 'print'
        puts s[a..b]
    when 'reverse'
        first = a == 0 ? '' : s[0..a-1]
        middle = s[a..b].reverse
        final = b == s.length-1 ? '' : s[b+1..-1]
        s = first + middle + final
    when 'replace'
        word = t[3]
        first = a == 0 ? '' : s[0..a-1]
        middle = word
        final = b == s.length-1 ? '' : s[b+1..-1]
        s = first + middle + final
    end
end


Measured memory_bytes: 8940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e18)+INF;
const double EPS = 1e-8;
using namespace std;
int main()
{
    int a,b,c;
    string s,t;
    cin >> a;
    cout << (a+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    string s;
    cin >> n >> s;
    ll r = 0;
    ll g = 0;
    ll b = 0;
    rep(i, n){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }
    ll ans = r * g * b;
    rep(i, n){
        REP(j, i + 1, n){
            ll k = j - i + j;
            if(k >= n) continue;
            if(s[i] == s[j] || s[i] == s[k] || s[j] == s[k]) continue;
            ans--;
        }
    }
    print(ans);



}




//queue<pint>().swap(q); キュー内を全て削除
//priority_queue<ll, vector<ll>, greater<ll> > que;
//auto dp=make_v<int>(4,h,w);
//vector<vector<ll>> g;
//g.assign(n, vector<ll>()); g.resize(n);でも大丈夫っぽい
//fill_v(dp,0);

Measured memory_bytes: 3656
/* *>>>>>Anshit_Bhardwaj<<<<<* */
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << ' ' << y << endl
#define dbg3(x, y, z) cout << x << ' ' << y << ' ' << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, a, cnt = 0;
    cin >> n;
    f(i, 1, n+1){
        cin >> a;
        if(i & 1){
            if(a & 1){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
while True:
    try:
        a = list(map(int, input().split()))
        b = list(map(int, input().split()))
        hit, blow = 0, 0
        for i in range(4):
            if a[i] == b[i]:
                hit += 1
            elif (b[i] in a) == 1:
                blow += 1
        print(hit, blow)
    except:
        break



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{






    int n;
    cin >> n;


    vector<int> a(n);
    vector<int> b(n);

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


    sort(a.begin(),a.end());

    sort(b.begin(),b.end());

    if(n%2 == 1)
    {
      cout << b[n/2] - a[n/2] + 1;
    }
    else
    {
      cout << b[n/2] + b[n/2-1]-a[n/2]-a[n/2-1] + 1;
    }



    return 0;
}


Measured memory_bytes: 6396
n=int(input())
nums=[0,0,0,0]
while n>0:
  s=input().strip()[0]
  if s=='A':
    nums[0] += 1
  elif s=='W':
    nums[1] += 1
  elif s=='T':
    nums[2] += 1
  elif s=='R':
    nums[3] += 1
  n -= 1
verds=['AC','WA','TLE','RE']
for i in range(4):
  print('{} x {}'.format(verds[i],nums[i]))


Measured memory_bytes: 9092
#include <iostream>
#include <algorithm>
int main(){
    using namespace std;
    int x, y;
    cin >> x >> y;

    int m,n,r;
    m = max(x, y);
    n = min(x, y);
    while(n != 0){
        r = m % n;
        m = n;
        n = r;
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ {
  public class AOJ {
    public static void Main(string[] args) {
      while(true) {
        int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        if(n[0] == 0 && n[1] == 0) break;
        string cache = new string('#', n[1]);
        for(int m = 0; m < n[0]; ++m) {
          Console.WriteLine(cache);
        }
        Console.WriteLine();
      }
    }
  }
}

Measured memory_bytes: 9288
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;


int prime[120000];
int sum[120000];

int main(){
    for(int i=2;i<=119999;i++){
        bool flag=true;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                flag=false;
                break;
            }
        }
        if(flag==true)prime[i]++;
        /*1が素数*/
    }
    sum[3]=1;
    int summ=1;
    int lastprime=3;
    for(int i=5;i<=119999;i=i+2){
        if(prime[i]==1&&prime[(i+1)/2]==1){
            for(int j=lastprime;j<=i;j++){
                sum[j]=summ;
            }
            lastprime=i;
            summ++;
        }
    }
    
    int q;cin>>q;
    for(int i=1;i<=q;i++){
        int l,r;cin>>l>>r;
        printf("%d\n",sum[r]-sum[l-1]);
    }
    return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		sc.close();
		if (x >= a) {
			System.out.println(10);
		} else {
			System.out.println(0);
		}
	}
}


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

namespace ConsoleApp23
{
    class Program
    {

        static void Main(string[] args)
        {
            // var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var s = Console.ReadLine();

            var len = s.Length;
            var first = s[0].ToString();
            var last = s[len - 1].ToString();

            Console.WriteLine(first + (len - 2).ToString() + last);
        }


    }

}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int kekka,kari;
  kekka=0;
  kari=0;
  string iti,ni;
  cin >> iti >> ni;
  for(int i=0;i<=iti.size()-ni.size();i++) {
    for(int s=0;s<ni.size();s++) {
      if(iti.at(i+s)==ni.at(s)) {
        kari++;
      }
    }
    if(kekka<kari) {
      kekka=kari;
    }
    kari=0;
  }
  cout << ni.size()-kekka << endl;
}

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

main(){
	int b,r,g,c,s,t ;
	while( cin>>b>>r>>g>>c>>s>>t ){
		if( !b && !r && !g && !c && !s && !t ) break ;
		
		int sum = 100 ;
		sum += b*6*15 +  + r*4*15 + g*7 + c*2 ;
		t -= s ;
		sum -= t*3 - b*5 - r*3 ;
		
		cout << sum << endl ;
	}
}

Measured memory_bytes: 1160
// D - People on a Line
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int in(){int x;scanf("%d",&x);return x;}

#define TMAX 100000
vector<pair<int,int>> T[TMAX+1];
int dist[TMAX+1];

void dfs(int p, int w){
	if(dist[p] != INT_MAX) return;
	dist[p] = w;
	for(auto cw:T[p]) dfs(cw.first, w+cw.second);
}

bool solve(){
	int N=in(), M=in();
	if(!M) return true;

	int L = INT_MAX, R = 0;
	while(M--){
		int l=in(), r=in(), d=in();
		L = min(L, l), R = max(R, r);
		T[l].emplace_back(r, d),
		T[r].emplace_back(l,-d);
	}

	while(N) dist[N--] = INT_MAX;
	rp(l, L, R+1){
		dfs(l, 0);
		for(auto rd:T[l]) if(rd.second != dist[rd.first]-dist[l]) return false;
	}
	return true;
}

int main(){
	puts(solve()?"Yes":"No");
}

Measured memory_bytes: 11008
class Dice:
    def __init__(self, U, S, E, W, N, D):
        self.u, self.d = U, D
        self.e, self.w = E, W
        self.s, self.n = S, N
    
    def roll(self, commmand):
        if command == 'E':
            self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e
        elif command == 'W':
            self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w
        elif command == 'S':
            self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s
        else:
            self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n

U, S, E, W, N, D = [int(i) for i in input().split()]
commands = input()
dice1 = Dice(U, S, E, W, N, D)
for command in commands:
    dice1.roll(command)
print(dice1.u)
    

            
            
            
            
        


Measured memory_bytes: 5612
n=int(input())
a = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    a.append(i)
    if i != n // i:
      a.append(n//i)
b = list(map(int,a))
anc =1000000000000
for l in range(len(b)):
  if int(n/b[l]+b[l])-2<anc:
    anc = int(n/b[l]+b[l])-2
print(anc)

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	int ans = 0;
	int r = 1;
	rep(l,n){
		while(r < n && a.at(r) <= a.at(r - 1)) r++;
		chmax(ans,r - l - 1);
		l = r - 1;
		r++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    ll n; cin >> n;
    int cnt = 0;
    ll a = 2;
    map<int, int> mp;
    while (n >= a * a) {
        if (n % a == 0) {
            mp[a]++;
            n /= a;
        }
        else a++;
    }
    if (n != 1) mp[n]++;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        int i = 1;
        while (1) {
            if (i * (i + 1) <= 2 * itr->second && 2 * itr->second < (i + 1) * (i + 2)) break;
            i++;
        }
        cnt += i;
    }
    cout << cnt << endl;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int ab, bc, ca;
    cin >> ab >> bc >> ca;

    cout << (ab * bc / 2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    REP(i,n){
        cin>>v[i];
    }
    sort(ALL(v));
    ll min=pow(10,9);
    REP(i,n-k+1){
        ll diff=v[i+k-1]-v[i];
        if(diff<min){
            min=diff;
        }
    }
    cout<<min;
    return 0;
}


Measured memory_bytes: 4000
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
VI e[SIZE];
int v[SIZE];
void dfs(int x,int lt){
    for(int y:e[x]){
        if(y==lt)continue;
        v[y]+=v[x];
        dfs(y,x);
    }
}
int main(){
    int N,Q;
    R(N,Q);
    FOR(i,1,N-1){
        int x,y;
        R(x,y);
        e[x].PB(y);
        e[y].PB(x);
    }
    REP(i,Q){
        int p, x;
        R(p,x);
        v[p]+=x;
    }
    dfs(1,1);
    W(VI(v+1,v+N+1));
    return 0;
}


Measured memory_bytes: 44928
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> n;
	vector<pair<pair<string, ll>,ll>> p(n);
	rep(i, n) {
		cin >> p[i].first.first >> p[i].first.second;
		p[i].second = i;
		p[i].first.second *= -1;
	}
	sort(p.begin(), p.end());
	rep(i, n) {
		cout << p[i].second + 1 << endl;
	}
}



Measured memory_bytes: 256