akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,K;
ll A[200005];
const ll max_n=1<<18;
ll dat1[2*max_n-1],dat2[2*max_n-1];
void add(ll a,ll b,ll x,ll k,ll l,ll r){
    if(a<=l&&r<=b){
        dat1[k]+=x;
    }
    else if(l<b&&a<r){
        dat2[k]+=(min(b,r)-max(a,l))*x;
        add(a,b,x,k*2+1,l,(l+r)/2);
        add(a,b,x,k*2+2,(l+r)/2,r);
    }
}
ll sum(ll a,ll b,ll k,ll l,ll r){
    if(b<=l||r<=a) return 0;
    else if(a<=l&&r<=b) return dat1[k]*(r-l)+dat2[k];
    else{
        ll res=(min(b,r)-max(a,l))*dat1[k];
        res+=sum(a,b,k*2+1,l,(l+r)/2);
        res+=sum(a,b,k*2+2,(l+r)/2,r);
        return res;
    }
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>K;
rep(i,N) cin>>A[i];
if(K>100){
	rep(i,N) cout<<N<<" ";
	cout<<endl;
	exit(0);
}
rep(k,K){
	fill(dat1,dat1+2*max_n,0);
	fill(dat2,dat2+2*max_n,0);
	rep(i,N){
		ll d=A[i];
		ll xleft=max((ll)0,i-d);
		ll xright=min(N-1,i+d);
		add(xleft,xright+1,1,0,0,N);
	}
	rep(i,N) A[i]=min(N,sum(i,i+1,0,0,N));
}
rep(i,N) cout<<A[i]<<" ";
cout<<endl;


}
	

Measured memory_bytes: 13404
// D - Even Relation
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
using PII = pair<int,int>;
using NODE = vector<PII>;
using TREE = vector<NODE>;

vl dist(100000+1, -1);

void dfs(TREE &T, int p, ll w){
	if(dist[p]>=0) return;
	dist[p] = w;
	for(auto c:T[p]){
		int np,nw; tie(np,nw) = c;
		dfs(T, np, w+nw);
	}
}

int main(){
	int N; cin>>N;
	TREE T(N+1, NODE());
	rpz(i, N-1){
		int u,v,w; cin>>u>>v>>w;
		T[u].emplace_back(v,w);
		T[v].emplace_back(u,w);
	}
	dfs(T, 1, 0);
	rpz(i,N) cout<< dist[i+1]%2 <<endl;
}

Measured memory_bytes: 8576
#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int num;
	while(cin >> num)
	{
		if(num == 0)
		{
			break;
		}
		int multipleOfFive = 5;
		vector<int> Vec;
		while(num >= multipleOfFive)
		{
			Vec.push_back(multipleOfFive);
			multipleOfFive *= 5;
		}
		int ans = 0;
		for(int i = 0; i < Vec.size(); ++i)
		{
			ans += num / Vec[i];
		}
		cout << ans << endl;
	}
}

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

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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define line printf("\n")
#define rep(a,b,c) for(int a= (int)b;a<(int)c;a++)
#define repd(a,b,c) for(int a=(int)b;a>=c;a--)
#define pb push_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define pq priority_queue
#define haha printf("hahaha\n")

const int INF = 1e9+7;
const ll INFLL = 1e17;
const double EPS = 1e-5;

using namespace std;

vector<int> adj[3005];
int flag[3005],deg[3005];
int n,m,d,rem;

int greedy(int);
int main(){
	scanf("%d%d%d",&n,&m,&d);
	
	for(int k=0;k<m;k++){
		int a,b;
		scanf("%d%d",&a,&b);a--;b--;
		
		adj[a].push_back(b);
		adj[b].push_back(a);
		deg[a]++;deg[b]++;
	}
	
	int tmp = greedy(d);
	if(tmp<0)printf("Impossible\n");else printf("%d\n",d-tmp);
	return 0;
}

inline void remove(int a){
	deg[a] = 0;
	rep(k,0,adj[a].size()){
		if(deg[adj[a][k]])deg[adj[a][k]]--;
	}
}
vector<int>rev[3005];
int greedy(int sisa){
	if(sisa<0)return sisa;
	int maks = 0;
	rep(k,0,n)rev[k].clear();
	rep(k,0,n)if(deg[k])rev[deg[k]].pb(k),maks = max(maks,deg[k]);
	
	if(maks==0)return sisa;
	int node;
	if(rev[1].size()){
		node = rev[1][0];
		rep(k,0,adj[node].size())if(deg[adj[node][k]]){
			node = adj[node][k];break;
		}
	}
	else{
		node = rev[maks][0];
	}
	//printf("|%d",node+1);line;
	remove(node);
	return greedy(sisa-1);
}

Measured memory_bytes: 1852
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		int m = ni();		
		int[] p = new int[m];
		String[] s = new String[m];
		for(int i = 0; i < m; i++) {
			p[i] = ni();
			s[i] = next();
		}
		
		boolean[] isac = new boolean[n + 1];
		int[] wacnt = new int[n + 1];
		int ac = 0;
		int wa = 0;
		for(int i = 0; i < m; i++) {
			if(isac[p[i]]) {
				continue;
			} else {
				if("AC".equals(s[i])) {
					ac++;
					isac[p[i]] = true;
				} else {
					wacnt[p[i]]++;
				}
			}
		}
		for(int i = 1; i <= n; i++) {
			if(isac[i]) {
				wa += wacnt[i];
			}
		}
		System.out.println(ac + " " + wa);
	}


	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 47060
#include <stdio.h>

#define MAX 100000
#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
}tree;

tree T[MAX];

int main(){
  
  int n,i,j,node,zisu,child,left,count,Npare,Nani;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
    T[i].l=NIL;
    T[i].r=NIL; 
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&node,&zisu);
    for(j=0;j<zisu;j++){
      if(j==0){
	scanf("%d",&child);
	T[node].l=child;
	T[child].p=node;
      }
      else {
	scanf("%d",&child);
	T[left].r=child;
	T[child].p=node;
      }
      left=child;
    }
  }

  for(i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].p);
    count=0;
    Npare=i;
    while(1){
      if(T[Npare].p==NIL) break;
      Npare=T[Npare].p;
      count++;
    }
    printf("depth = %d, ",count);
    if(T[i].p==NIL){
      printf("root, ");
    }
    else if(T[i].l==NIL && T[i].p!=NIL){
      printf("leaf, ");
    }
    else{
      printf("internal node, ");
    }
    printf("[");
    if(T[i].l !=-1){
      printf("%d",T[i].l);
      Nani= T[i].l;
      while(1){
	if(T[Nani].r==-1)break;
	printf(", %d",T[Nani].r);
	Nani=T[Nani].r;
      }
    }
    printf("]\n");	
  }
  
  return 0;
}

Measured memory_bytes: 1788
#include<stdio.h>

int main(){
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    if (x > y) {
        printf("a > b\n");
    } else if (x < y) {
        printf("a < b\n");
    } else {
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2004
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll n, k;
	cin >> k;
	queue<ll>qu;
	for (ll i = 1; i < 10; i++) {
		qu.push(i);
	}
	if (k <= 9) {
		cout << k << endl;
		return 0;
	}
	ll i = 9,node,lst,nxt;
	while (i < k) {
		node = qu.front();
		qu.pop();
		lst = node % 10;
		if (lst) {
			nxt = node * 10 + lst - 1;
			if (i + 1 == k) {
				cout << nxt << endl;
				return 0;
			}
			qu.push(nxt);
			i++;
		}
		nxt = node * 10 + lst;
		if (i + 1 == k) {
			cout << nxt << endl;
			return 0;
		}
		qu.push(nxt);
		i++;

		if (lst<9) {
			nxt = node * 10 + lst + 1;
			if (i + 1 == k) {
				cout << nxt << endl;
				return 0;
			}
			qu.push(nxt);
			i++;
		}
	}
	return 0;
}

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

using namespace std;

int main() {
  int n,m;
  while(cin >> n &&  n){
    int grid[25][25]={};
    int x,y,sum=0;
    for(int i=0;i<n;++i){
      cin >> x >> y;
      grid[x][y]++,sum++;
    }
    cin >> m;
    int d,dx,dy,nx=10,ny=10;
    char c;
    for(int i=0;i<m;++i){
      cin >> c >> d;
      if(c=='N') dx=0,dy=1;
      else if(c=='E') dx=1,dy=0;
      else if(c=='S') dx=0,dy=-1;
      else if(c=='W') dx=-1,dy=0;
      for(int j=0;j<d;++j){
	nx+=dx,ny+=dy;
	if(grid[nx][ny]) grid[nx][ny]--,sum--;
      }
    }
    if(sum) cout << "No" <<endl;
    else cout << "Yes" <<endl;
  }
  
  return 0;
}


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

using namespace std;


int main()
{
  int n;
  cin >> n;
  
  unordered_map<int, int> a;
  
  for(int i=0; i<n; i++){
    int tmp;
    cin >> tmp;
    a[tmp]++;
  }
  
  int count=0;
  for(auto itr = a.begin(); itr!=a.end(); itr++){
    if(itr->second % 2)
      count++;
  }
  
  cout << count << endl;

  return 0;
}

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

int main()
{
    int times = 0;
    string S = "";
    cin >> S;
    for ( int i = 0; i < S.size(); i++ )
    {
        if ( S[i] == 'o' )
        {
            times ++;
        }
    }

    if ( 15 - S.size() + times >= 8 )
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    string s; cin >> s;
    cout << s.substr(0,3) << endl;
}

Measured memory_bytes: 3624
fun main(arr:Array<String>) {
    val dic = mutableMapOf<Int, Int>()
    listOf(1,3,5,8,7,10,12).forEach { dic[it] = 0 }
    listOf(4,6,9,11).forEach { dic[it] = 1 }
    dic[2] = 2

    val xy = readLine()!!.split(" ").map { it.toInt() }
    val ans = if(xy.map { dic[it]!! }.distinct().size == 1) "Yes" else "No"
    println(ans)
}

Measured memory_bytes: 37956
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
count = 0

for i in range(n):
    if i == n - 1:
        if x == min(list2):
            count = count + 1
        else:
            break
    elif x >= min(list2):
        x = x - min(list2)
        list2.remove(min(list2))
        count = count + 1
    else:
        break
print(count)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int result = 1;
		for(int i = n; i <= m/2; i++){
		    if(m%i == 0){
		        result = m/i;
		        break;
		    }
		}
		
		// 出力
		System.out.println(result);
		
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

const int N = 1e5 + 5;

struct BIT {
	int t[2*N];
	void edit(int x,int val){
		x+=N;
		for(++x;x<2*N;x+=(x&-x)){
			t[x] += val;
		}
	}
	int query(int x){
		int res = 0;
		x+=N;
		for(++x;x;x &= x - 1){
			res += t[x];
		}
		return res;	
	}
	void clear(){
		memset(t,0,sizeof(t));
	}
} tree;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> v(n);
	ll sub = 1LL * n * (n - 1)/2 + n;
	rep(i,0,n)cin >> v[i];
	int l = 0, r = 1e9+1;	
	int ans = 0;
	while(l <= r){
		tree.clear();
		int m = l + (r-l)/2;
		int rsum = 0;
		tree.edit(0,1);
		ll cnt = 0;
		rep(i,0,n){
			if(v[i] <= m)++rsum;
			else --rsum;
			cnt += tree.query(rsum-1);
			tree.edit(rsum,1);
		}
		if(cnt * 2 > sub){
			ans = m;	
			r = m - 1;
		}
		else{
			l = m + 1;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
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;
    cout << pow(n,3) << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    class Program
    {

        static long n;

        static int Tile(long i, long j)
        {
            long a = n / 2;

            if(n % 2 == 1)
            {
                a = a + 1;
            }

            if (i > a)
            {
                i = 1 + n - i;
            }
            if (j > a)
            {
                j = 1 + n - j;
            }

            long u = Math.Min(i, j);

            if(u % 3 == 1)
            {
                return 1;
            }
            else if(u % 3 == 2)
            {
                return 2;
            }
            else
            {
                return 3;
            }

        }

        static void Main(string[] args)
        {

            n = long.Parse(Console.ReadLine());
            long q = long.Parse(Console.ReadLine());

            for(int k = 0; k < q; k++)
            {
                string[] str = Console.ReadLine().Split(' ');

                long i = long.Parse(str[0]);
                long j = long.Parse(str[1]);

                Console.WriteLine(Tile(i, j));
            }
            

        }
    }
}



Measured memory_bytes: 15896
n = int(input())
arrey = [int(i) for i in input().split()]
count = 0

for i in range(len(arrey)):
    minj = i
    change = False
    for j in range(i+1, len(arrey)):
        if arrey[minj] > arrey[j]:
            minj = j
            change = True
    if change:
        arrey[i], arrey[minj] = arrey[minj], arrey[i]
        count += 1

for i in range(len(arrey)):
    print(str(arrey[i])+' ',end='') if i != len(arrey)-1 else print(arrey[i])
print(count)

Measured memory_bytes: 7664
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a;
    cin >> a;
    ll hash[256] = {};
    ll ans =  1 + a.size() * (a.size() - 1) / 2;
    REP(i, a.size()){
        hash[(int)a[i]]++;
    }
    FOR(i, 'a', 'z'){
        ans -= hash[i] * (hash[i] - 1) / 2;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 720
n=int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

tmp = T - H[0] * 0.006
ans = 1

for i in range(len(H)):
    
    if abs(tmp - A) > abs(T-H[i] * 0.006 - A):
        tmp = T-H[i] * 0.006
        ans = i + 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

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

void solve(){
	int n;
	cin >> n;
	ll a[n];
	for(int i =0;i<n;i++)
		cin >> a[i];
	ll ans = 0;

	forn(i,1,n){
		if(a[i]<=a[i-1]){
			ans+=a[i-1] - a[i];
			a[i] = a[i-1];
		}
	}
	cout << ans << endl;
}


int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 5216
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
    string S;
    string S_1 = "";
    string S_2 = "";
    bool ans = true;

    cin >> S;

    int s = 0;
    int l = S.length();
    while(s < (l - 1) / 2)
    {
        if (S[s] != S[l - 1 - s])
        {
            ans = false;
            break;
        }
        s++;
    }

    s = 0;
    while (s < l)
    {
        if (s < (l - 1) / 2)
            S_1 += S[s];

        if (s >= ((l + 3) / 2) - 1)
            S_2 += S[s];

        s++;
    }

    s = 0;
    l = S_1.length();
    while (s < l / 2)
    {
        if (S_1[s] != S_1[l - 1 - s])
        {
            ans = false;
            break;
        }
        s++;
    }

    s = 0;
    l = S_2.length();
    while (s < l / 2)
    {
        if (S_2[s] != S_2[l - 1 - s])
        {
            ans = false;
            break;
        }
        s++;
    }

    if (ans)
        cout << "Yes";
    else
        cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define abs(a) ((a)<0 ? -(a) : (a))
int main(){
  int n;  scanf("%d", &n);
  int nowt = 0, nowx = 0, nowy = 0;
  int nt, nx, ny;
  for(int i=0; i<n; i++){
    scanf("%d%d%d", &nt, &nx, &ny);
    if(nx == nowx && ny == nowy){
      if((nt-nowt)%2){
	printf("No\n");
	return 0;
      }
    }
    int ttt = nt - nowt - (abs(nx-nowx)+abs(ny-nowy));
    if(!( ttt == 0 || (ttt > 0 && ttt%2==0) )){
      printf("No\n");
      return 0;
    }
    nowt = nt, nowx = nx, nowy = ny;
  }
  printf("Yes\n");
  return 0;
}


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

using namespace std;
typedef long long ll;
const int maxn = 3e5 + 50;
int a[maxn];
ll bestsum[maxn][2];


int main(){
  int n; cin >> n;
  for(int i=0;i<3*n;i++){
    cin >> a[i];
  }
  ll S = 0;
  priority_queue<int, vector<int>, greater<int> > Q;
  for(int i=0;i<n;i++){
    S += a[i];
    Q.push(a[i]);
  }
  for(int i = n-1; i < 2 * n; i++){
    bestsum[i][0] = S;
    S += a[i+1];
    Q.push(a[i+1]);
    S -= Q.top();
    Q.pop();
  }
  priority_queue<int> QQ;
  S = 0;
  for(int i = 2 * n; i < 3 * n; i++){
    S += a[i];
    QQ.push(a[i]);
  }
  for(int i = 2 * n - 1; i >= n - 1; i--){
    bestsum[i][1] = S;
    QQ.push(a[i]);
    S += a[i];
    S -= QQ.top();
    QQ.pop();
  }
  ll ans = -1e15;
  for(int i=n-1;i<2*n;i++){
    ans = max(ans, bestsum[i][0] - bestsum[i][1]);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 5112
n = int(input())
xm = list(map(int, input().split()))
xm_sort = sorted(xm)
a = n//2-1
for i in range(n):
    if xm[i]<=xm_sort[a]:
        print(xm_sort[a+1])
    else:
        print(xm_sort[a])

Measured memory_bytes: 26016
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <numeric>
#include <unordered_map>
using namespace std;
int main() {
	int N, now = 0, d[100] = {}, sum = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}
	sort(d, d + N);
	for (int i = 0; i < N; ++i) {
		if (d[i] > now) {
			now = d[i];
			sum++;
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n % 2 == 0 ? n : n * 2);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

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

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

	for(int n; cin >> n && n;) {
		int cnt = 0;
		while(n > 1) {
			++cnt;
			if(n & 1) {
				n = n * 3 + 1;
			}
			else {
				n >>= 1;
			}
		}
		cout << cnt << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
n = int(input())
d = []
for i in range(1,n+1):
    city, score = input().split()
    d.append({'id':i, 'restaurant':{'city':city, 'score':int(score)}})

sorted_d = sorted(
    d,
    key = lambda x: (x['restaurant']['city'], -x['restaurant']['score'])
)

for l in sorted_d:
    print (l['id'])


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

int rmv(int curr, int count) {
  if (count >= curr) {
    return count - curr;
  } else {
    return count;
  }
}

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

  int n;
  cin >> n;

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

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

  queue<int> q;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] != a[i]) {
      q.push(i - 1);
    }
  }
  q.push(n - 1);

  int ans = 0;
  int cc = 0;
  for (int i = 0; i < n; i++) {
    cc++;

    if (q.front() == i) {
      ans += rmv(a[i], cc);

      cc = 0;
      q.pop();
    }
  }

  cout << ans << endl;

  return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<int> A, B;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, ans=0, c=0;
	cin>>N;
	A.resize(N);
	B.resize(N);
	for(auto &a: A) cin>>a;
	for(int i=0;i<N;i++) {
		cin>>B[i];
		A[i]-=B[i];
	}
	sort(A.begin(),A.end());
	for(int i=0;i<A.size();i++) {
		if(A[i]>=0) break;
		ans++;
		while(A[i]<0) {
			int m;
			if(c==0) {
				ans++;
				if((c=A.back())<=0) {
					cout<<"-1\n";
					return 0;
				}
				A.pop_back();
			}
			m=min(c,-A[i]);
			A[i]+=m;
			c-=m;
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
        int a,b,c,v1,v2,v3;
        cin >> a >> b >> c;
        v1 = a;v2= b;v3=c;
        if (a>b) {v1=b;v2=a;}
        else {v1=a,v2=b;}
        if (v2>c) {v3=v2;v2=c;}
        else {v3=c;}
        if (v1>v2) {a=v2;b=v1;}
        else {a=v1;b=v2;}
        cout << a <<" "<< b <<" "<< v3 <<endl;
        return 0;
}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

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

  for(ll i=1;i<=n;i++){
    ll nn=n/i;
    ans+=(nn*(nn+1)/2)*i;
  }


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

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

class Solver{};

int main() {
	while (true) {
		int r, a;
		cin >> r >> a;
		if (r == 0)break;

		map<int, int> mp;
		for (int i = 0; i < 4; i++) {
			int div = pow(10, i);
			mp.emplace((r / div) % 10, i);
		}

		int h = 0;
		int b = 0;
		for (int i = 0; i < 4; i++) {
			int div = pow(10, i);
			int val = (a / div) % 10;
			if (mp.find(val) != mp.end()) {
				if (mp[val] == i)h++;
				else b++;
			}
		}

		cout << h << " " << b << endl;
	}
}


Measured memory_bytes: 3132
import sys
sys.setrecursionlimit(1000000)

def acinput():
    return list(map(int, input().split(" ")))


N, M = acinput()
a = [0]*(N+1)
for i in range(M):
    a[int(input())] = 1


Mod = 1000000007


def solve(x):
    global dp, Mod
    if dp[x] >= 0:
        return dp[x]

    if x < 0:
        return 0

    res = 0
    zeroflg = True

    if  a[x-2] != 1:
        res += solve(x-2) 
        zeroflg = False

    if a[x-1] != 1:
        res += solve(x-1)
        zeroflg = False

    if zeroflg:
        return 0
    dp[x] = res% Mod
    return res


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

print(solve(N) % Mod)


'''
5 1
1
'''


Measured memory_bytes: 52056
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.NextInt();
			int x = n % 10;
			if (x == 3) Console.WriteLine("bon");
			else if (x == 0 || x == 1 || x == 6 || x == 8) Console.WriteLine("pon");
			else Console.WriteLine("hon");

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 27372
H, W = map(int, input().split())
grid = []
answer = 'Yes'
for i in range(H):
    grid.append(list(input()))

for i in range(H):
    for j in range(W):
        tonari = []
        if i != 0:
            tonari.append(grid[i-2][j-1])
        if i != H:
            tonari.append(grid[i][j-1])
        if j != 0:
            tonari.append(grid[i-1][j-2])
        if j != W:
            tonari.append(grid[i-1][j])
            
        if '#' not in tonari and grid[i-1][j-1] == '#':
            answer = 'No'
print(answer)

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

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

    string S; cin >> S;

    int n = 0;
    int len = 0;
    for (uint32_t i = 0; i < S.size(); i++) {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
            n++;
        } else {
            n = 0;
        }
        if (len < n) len = n;
    }

    cout << len << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,pll> ppll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); 
const ll M = 1e9 + 7;

int main() {
    FAST;
    ll n, x = 0, y = 0, k, i, t, ans = 0, j, c = 0, z = 0, m;
    cin >> n;
    map < ll , ll > mp;
    for ( i = 0 ; i < n ; i ++ ){
    	cin >> x;
    	if ( mp[x] == 1 ) out("NO");
    	mp[x] = 1;
    }
    cout << "YES";
}

Measured memory_bytes: 12800
import sys
input = sys.stdin.readline

S=input().strip()
LEN=len(S)

flag=1

for i in range(LEN):
    if i%2==1:
        if S[i]=="R":
            flag=0

    else:
        if S[i]=="L":
            flag=0

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
program find_symmetries
  implicit none
  integer :: n, s(600,300), m, a, i, j
  character(300) :: t
  logical :: ng
  s = 0
  read(*,*) n
  do i = 1, n
    read(*,*) t
    t = trim(adjustl(t))
    do j = 1, n
      s(i,j) = ichar(t(j:j))-97
    end do
    s(i+n,1:n) = s(i,1:n)
  end do
  m = 0
  do a = 0, n-1
    ng = .false.
    do i = 1, n
      do j = 1, n
        if (s(i+a,j).ne.s(j+a,i)) then
          ng = .true.
          exit
        end if
      end do
      if (ng) exit
    end do
    if (.not.ng) m = m + 1
  end do
  write(*,'(i0)') n*m
  stop
end program find_symmetries

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

int main(){
  int distance=0, speed=0, timelim=0;
  cin >> distance;
  cin >> timelim;
  cin >> speed;
  if(timelim*speed >= distance){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3592
N=int(input())
H=list(map(int,input().split()))
x=0
y=0
for i in range(N-1):
    if H[i]>=H[i+1]:
        y+=1
    else:
        if y>x:
            x=y
        y=0
if y>x:
    x=y
print(x)

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

int main(){
  int r, c;
  cin >> r >> c;
  vector<vector<int>> data(r, vector<int>(c));
  for(int i = 0; i < r; i++){
    for(int j = 0; j < c; j++){
      cin >> data.at(i).at(j);
    }
  }
  vector<int> last(c + 1);
  for(int i = 0; i <= r; i++){
    int answer= 0;
    if(i == r){
      for(int i = 0; i < c + 1; i++){
        if(i != c){ 
          last.at(c) += last.at(i);
          cout << last.at(i) << " ";
        }
        else if(i == c){
          cout << last.at(i) << endl;
        }
      }
      break;
    }
    for(int j = 0; j <= c; j++){
      if(j == c){
        cout << answer << endl;
        continue;
      }
      answer += data.at(i).at(j);
      last.at(j) += data.at(i).at(j); 
      cout << data.at(i).at(j) << " ";
    }
  }
  
}



Measured memory_bytes: 3164
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int a,count=0;
    cin>>a;
    int b[a];
    for(int i=0;i<a;i++){
        cin>>b[i];
    }
    for(int i=1;i<a-1;i++){
        if( (b[i]<b[i-1] && b[i]>b[i+1]) || (b[i]>b[i-1] && b[i]<b[i+1]) ){
            count++;
        }
    }
    cout<<count<<endl;

}


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

using namespace std;

int main()
{
  int n;
  while(cin >> n, n){
    string prv = "";
    int cnt = 0;
    while(n--){
      string f;
      cin >> f;
      if(prv == "lu" && f == "ru" ||
	 prv == "ru" && f == "lu" ||
	 prv == "ld" && f == "rd" ||
	 prv == "rd" && f == "ld") cnt++;
      prv = f;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

//-----------------------ここから-----------

int main(void){
    ld n, t, a;
    cin >> n >> t >> a;

    vector<ld> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    ld ans = 1e9;
    int ansIndex = 0;

    for(int i = 0; i < n; i++){
        ld diff = abs(a - (t - h[i] * 0.006));
        if(diff < ans){
            ans = diff;
            ansIndex = i;
        }
    }

    cout << ansIndex + 1 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, q, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<vector<P>> vp(n + 1);

  REP(i, n - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    vp[a].push_back(P(b, c));
    vp[b].push_back(P(a, c));
  }

  cin >> q >> k;

  vector<ll> d(n + 1);
  queue<P> que;
  que.push(P(k, - 1));
  while(!que.empty()) {
    P p = que.front(); que.pop();

    REP(i, vp[p.first].size()) {
      if(vp[p.first][i].first != p.second) {
        d[vp[p.first][i].first] = (ll)d[p.first] + vp[p.first][i].second;
        que.push(P(vp[p.first][i].first, p.first));
      }
    }
  }

  REP(i, q) {
    int x, y;
    cin >> x >> y;

    cout << d[x] + d[y] << endl;
  }
}


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

int main()
{
     int N;
     while (cin >> N, N) {
          vector<int> v;
          int tmp;
          for (int i = 0; i < N; i++) {
               cin >> tmp;
               v.push_back(tmp);
          }
          stable_sort(v.begin(), v.end());
          int sum = 0;
          for (int i = 1; i < v.size() - 1; i++) sum += v[i];
          sum /= (N - 2);
          cout << sum << endl;
     }

     return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[220]={},ans=0;
	cin>>n;
	for(int i=1;i<=2*n;i++) cin>>a[i];
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2)
	{
		ans+=a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    S = sorted(["".join(sorted(input())) for _ in range(N)])
    #print(S)
    ans = 0
    cnt = 0
    for i in range(1, N):
        if S[i-1] == S[i]:
            if cnt == 0:
                cnt = 2
            else:
                cnt += 1
        else:
            if cnt != 0:
                ans += cnt*(cnt-1)//2
            cnt = 0
    if cnt != 0:
        ans += cnt*(cnt-1)//2
    print(ans) 
    


    
if '__main__' == __name__:
    resolve()

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

using namespace std;

#define ll long long

int main()
{
    int now, n, l, sum = 0, mn = 1000;
    cin >> n >> l;
    for (int i=1; i<=n; ++i) {
        now = l + i - 1;
        if (abs(mn) > abs(now))
            mn = now;
        sum += now;
    }

    cout << sum - mn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <sstream>
using namespace std;

int top = 0;
int last = 0;
int s[1000010];
string name[1000010];

void push(string a, int n){
	s[last] = n;
	name[last] = a;
	++last;
}

int front_time(){
	return s[top];
}

string front_name(){
	return name[top];
}

void pop(){
	++top;
}

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

	int n, q;
	cin >> n >> q;

	for(int i = 0; i < n; ++i){
		string name;
		int t;
		cin >> name >> t;
		push(name, t);
	}

	int ntime = 0;
	while(top < last){
		int a = front_time();
		if(a <= q){
			ntime += a;
			cout << front_name() << " " << ntime << endl;
			pop();
		}
		else {
			a -= q;
			ntime += q;
			push(front_name(), a);
			pop();
		}
	}

	return 0;
}

Measured memory_bytes: 13792
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.next()
    val b = sc.next()
    val c = sc.next()

    if (a == b && b != c ||
        a == c && b != c ||
        b == c && a != b) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 31268
N = int(input())
X = list(map(int, input().split()))
sort_X = sorted(X)       
v1 = sort_X[N//2-1]
v2 = sort_X[N//2]
for i in range(N):
    if(X[i] <= v1):
         print(v2)
    else:     
         print(v1)

Measured memory_bytes: 25620
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

const int N = 2e5+7;

int n, k, ile, u, res;

int cnt[N];

VI v;

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

	cin >> n >> k;

	while(n--)
	{
		int a;
		cin >> a;
		++cnt[a];
	}

	for(int i = 0; i < N; ++i)
	{
		if(cnt[i])
			++ile;
	}

	u = max(0, ile-k);

	for(int i = 0; i < N; ++i)
	{
		if(cnt[i])
			v.pb(cnt[i]);
	}

	sort(ALL(v));

	for(int i = 0; i < u; ++i)
	{
		res += v[i];
	}

	cout << res;
}

Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 200005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll sz[N];
vector<int>ed[N];
int n;
ll fact[N];
ll ans[N];
ll dp[N];
long long powmod(long long a,long long b){
	if(b==0)return 1;
	long long c=powmod(a,b/2ll);
	c=((c*c)%mod*((b&1ll)?a:1ll))%mod;
	return c;
}
ll getinv(ll i){
	return powmod(i,mod-2);
}
void dfs(int i,int p){
	for(int j:ed[i]){
		if(j==p)continue;
		dfs(j,i);
		sz[i]+=sz[j];
	}
	sz[i]++;
	dp[i]=fact[sz[i]-1];
	for(int j:ed[i]){
		if(j==p)continue;
		dp[i]=(dp[i]*dp[j]%mod*getinv(fact[sz[j]]))%mod;
	}
}
void dfs1(int i,int p){
	if(p==0)ans[i]=dp[i];
	else ans[i]=(ans[p]*fact[sz[i]]%mod*fact[n-sz[i]-1]%mod*getinv(fact[sz[i]-1])%mod*getinv(fact[n-sz[i]]))%mod;
	for(int j:ed[i]){
		if(j==p)continue;
		dfs1(j,i);
	}
}
void solve(){
	cin>>n;
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	dfs(1,0);
	dfs1(1,0);
	for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	fact[0]=fact[1]=1;
	for(ll i=2;i<N;i++)fact[i]=(fact[i-1]*i)%mod;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 20212
s = input()
now = len(s)
while 1:
    flag = 1
    if 7 <= now:
        if s[now-7:now] == "dreamer":
            now -= 7
            flag = 0
    if 6 <= now:
        if s[now-6:now] == "eraser":
            now -= 6
            flag = 0
    if 5 <= now:    
        if s[now-5:now] == "erase":
            now -= 5
            flag = 0
        if s[now-5:now] == "dream":
            now -= 5
            flag = 0
    if flag:
        print("NO")
        exit()
    if now == 0:
        print("YES")
        exit()
    elif now < 5:
        print("NO")
        exit()

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

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

  int ans = 0;

  vector<int> st;
  for (int i = 0; i < S.size(); ++i) {
    st.push_back(S[i] == '1');

    while (st.size() >= 2) {
      int sz = st.size();
      if (st[sz - 1] != st[sz - 2]) {
        ans += 2;
        st.pop_back();
        st.pop_back();
      } else {
        break;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1020
N, M = map( int, input().split())
A = list( map( int, input().split()))
T = [(0,0)]*M
for i in range(M):
    b, c = map( int, input().split())
    T[i] = (c,b)
T.sort(reverse = True)
D = [-1]*N
cnt = 0
for i in range(M):
    c, b = T[i]
    for _ in range(b):
        D[cnt] = c
        cnt += 1
        if cnt >= N:
            break
    if cnt >= N:
        break
A.sort()
for i in range(N):
    if D[i] == -1:
        break
    if D[i] > A[i]:
        A[i] = D[i]
    else:
        break
print( sum(A))


Measured memory_bytes: 67176
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
#include <math.h>
#include <string>
#include <queue>

using namespace std;

int map[1001][1001];
int flg[1001][1001];


int main()
{
	int H, W;
	cin >> H >> W;

	char buff[1024];
	queue<pair<int, int>> q;

	for (int i = 0; i < H; i++)
	{
		cin >> buff;

		for (int j = 0; j < W; j++)
		{
			if (buff[j] == '#')
			{
				map[i][j] = 0;
				flg[i][j] = 0;
				q.push(make_pair(j, i));
			}
			else
			{
				map[i][j] = 1;
				flg[i][j] = -1;
			}
		}
	}

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

	while (!q.empty())
	{
		int x = q.front().first;
		int y = q.front().second;
		q.pop();

		maxd = max(maxd, flg[y][x]);
		int d = flg[y][x] + 1;

		for (int i = 0; i < 4; i++)
		{
			int rx = x + dx[i];
			int ry = y + dy[i];

			if (rx < 0 || rx > W || ry < 0 || ry > H)
			{
				continue;
			}

			if (map[ry][rx] != 0)
			{
				if (flg[ry][rx] == -1)
				{
					flg[ry][rx] = d;
					q.push(make_pair(rx, ry));
				}
			}

		}
	}

	cout << maxd << endl;

	return 0;
}

Measured memory_bytes: 16272
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint h(n);
  rep(i,n){
    cin>>h[i];
  }
  bool fg=false,fg2=false;;
  int count=0;
  while(true){
    fg=true;
    fg2=false;
    rep(i,n){
      if(fg2){
        if(h[i]==0){
          count++;
          fg2=false;
        }
        else{
          h[i]--;
        }
      }
      else{
        if(h[i]!=0){
          fg=false;
          fg2=true;
          h[i]--;
        }
      }
    }
    if(fg){
      break;
    }
    if(fg2){
      count++;
    }
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vi a(A);
	vi b(B);
	int min_a = int_INF;
	int min_b = int_INF;
	rep(i, A) {
		cin >> a[i];
		a[i] < min_a ? min_a = a[i] : 1;
	}
	rep(i, B) {
		cin >> b[i];
		b[i] < min_b ? min_b = b[i] : 1;
	}

	int ans = min_a + min_b;

	rep(j, M) {
		int x, y, c;
		cin >> x >> y >> c;
		x--;
		y--;
		if (a[x] + b[y] - c < ans) {
			ans = a[x] + b[y] - c;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    string S;
    cin >> S;
    if (S=="ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll R[N+1];
  R[0] = 0;
  for (int i = 0; i < N; i++) {
    R[i+1] = R[i] + A[i];
    R[i+1] %= Mod;
  }
  ll ans = 0;
  for (int i = 1; i < N; i++) {
    ll res = A[i] * R[i];
    res %= Mod;
    ans += res;
    ans %= Mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6772
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
static const int MAX_N = 100000;

int N, M;
vector<int> G[MAX_N + 1];
int indegree[MAX_N + 1];
int par[MAX_N + 1];

vector<int> TopologicalSort(){
	vector<int> va;
	queue<int> qa;
	for(int i = 1; i <= N; i++){
		if(indegree[i] == 0) qa.push(i);
	}
	while(!qa.empty()){
		int u = qa.front(); qa.pop();
		va.push_back(u);
		for(int i = 0; i < G[u].size(); i++){
			int v = G[u][i];
			indegree[v]--;
			if(indegree[v] == 0) qa.push(v);
		}
	}
	return va;
}

int main(){
	scanf("%d %d", &N, &M);
	for(int i = 0; i < N + M - 1; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		G[u].push_back(v);
		indegree[v]++;
	}
	vector<int> va = TopologicalSort();
	for(int i = 0; i < N; i++){
		for(int j = 0; j < G[va[i]].size(); j++){
			par[G[va[i]][j]] = va[i];
		}
	}
	for(int i = 1; i <= N; i++) printf("%d\n", par[i]);
	return 0;
}

Measured memory_bytes: 7544