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

using namespace std;

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

int main() {
	string str[5] = {"afkpuz","bglqv.","chmrw?","dinsx!","ejoty "};
	string in;
	
	while (cin >> in) {
		string ans = "";
		
		if (in.size() & 1) {
			puts("NA");
			continue;
		}
		REP(i, in.size() / 2) {
			int pos = i * 2;
			int a = in[pos] - '0', b = in[pos + 1] - '0';
			if (!(a >= 1 && a <= 6 && b >= 1 && b <= 5)) {
				ans = "NA";
				break;
			}
			a--; b--;
			ans += str[b][a];
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

vector<int> v;

int main(){

    int a, b;
    scanf("%d%d", &a, &b);
    int cnt=0;

    for(int i=a; i<=b; ++i){
        v.clear();
        int num=i;
        while(num){
            v.push_back(num%10);
            num/=10;
        }
        int sz=v.size();
        bool pal=true;
        for(int i=0, j=sz-1; i<j ; ++i, --j){
            if(v[i]!=v[j])
                pal=false;
        }
        if(pal)
            ++cnt;
    }

    printf("%d\n", cnt);








    return 0;
}


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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;
    vector<ll> L(N+1);

    L[0] = 2; L[1] = 1;
    for (int i = 2; i <= N; i++)
        L[i] = L[i - 1] + L[i - 2];

    cout << L[N] << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  vector<vector<int>> G_B(29,vector<int>(N)),G_A(N,vector<int>(29));
  for(int i=0; i<N; i++){
    for(int j=0; j<29; j++){
      G_A[i][j] = A[i]%(1LL<<(j+1));
      G_B[j][i] = B[i]%(1LL<<(j+1));
    }
  }
  for(int i=0; i<29; i++){
    sort(G_B[i].begin(),G_B[i].end());
  }
  vector<ll> cnt(29,0);
  for(int i=0; i<N; i++){
    for(int j=0; j<29; j++){
      cnt[j] -= lower_bound(G_B[j].begin(),G_B[j].end(),1LL*(1LL<<j)-G_A[i][j]) - G_B[j].begin();
      cnt[j] += lower_bound(G_B[j].begin(),G_B[j].end(),2LL*(1LL<<j)-G_A[i][j]) - G_B[j].begin();
      cnt[j] -= lower_bound(G_B[j].begin(),G_B[j].end(),3LL*(1LL<<j)-G_A[i][j]) - G_B[j].begin();
      cnt[j] += lower_bound(G_B[j].begin(),G_B[j].end(),4LL*(1LL<<j)-G_A[i][j]) - G_B[j].begin();
    }
  }
  ll ans = 0;
  for(int i=0; i<29; i++){
    ans += (1LL<<i) * (cnt[i]%2);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 57244
#include<bits/stdc++.h>
using namespace std;
   
int main(){
    long long int N, ans = 0;
    cin >> N;
    for(long long int i = 0; i <= N; i++){
        if(i % 3 && i % 5){
            ans += i;
        }
    }
    cout << ans << endl;
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

vector<int> a(200001);
ll ans = 0;

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

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

    sort(a.begin(), a.end());
    
    REPN_REV(i, 1, 200001) {
        if(a[i] > 0) {
            n -= a[i];
            k--;
        }
        if(k == 0) break;
    }

    cout << n << endl;

    return 0;
}
 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
const int INF=0x3f3f3f3f;
int d[8][2]={-1,0,0,-1,0,1,1,0,1,1,-1,-1,-1,1,1,-1};
int n,m,k;
char s[10];
int dp[15][15],sum=0;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)
        scanf("%d",&dp[i][j]);
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<10;j++)
        {
            for(int k=0;k<10;k++)
            dp[j][k]=min(dp[j][k],dp[j][i]+dp[i][k]);
        }
    }
    int t=n*m;
    while(t--)
    {
        scanf("%d",&n);
        if(n!=-1&&n!=1)
        sum+=dp[n][1];
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int b,r,j,k,i,c,a[101][101],t;
  scanf("%d%d",&r,&c);
  for(i=0;i<r;i++){
    t=0;
    for(j=0;j<c;j++){
      scanf("%d",&a[i][j]);
      t+=a[i][j];
    }
    a[i][c]=t;
  }
  for(i=0;i<=c;i++){
    t=0;
    for(j=0;j<r;j++){
      t+=a[j][i];
    }
    a[r][i]=t;
  }
  for(i=0;i<=r;i++){
    for(j=0;j<=c;j++){
      k=a[i][j];
      b=k;
      printf("%d",b);
      if(j!=c){
	printf(" ");
      }
      b=0;
    }


    printf("\n");
  }
  return (0);
}

      

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

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[][] us = new int[n][n];
        while (n-- > 0) {
            int u = input.nextInt();
            int k = input.nextInt();
            while (k-- > 0) {
                int v = input.nextInt();
                us[u-1][v-1] = 1;
            }
        }
        for (int[] xx : us) {
            StringBuilder sb = new StringBuilder();
            for (int x : xx) {
                sb.append(x).append(' ');
            }
            System.out.println(sb.toString().trim());
        }
    }
    
    void swap(int[] A, int x, int y) {
        int temp = A[x];
        A[x] = A[y];
        
        A[y] = temp;
    }
    
}

class Scanner {
    BufferedReader r;
    StreamTokenizer st;
    
    public Scanner(InputStream in) {
        r = new BufferedReader(new InputStreamReader(in));
        st = new StreamTokenizer(r);
    }
    
    public String next() {
        nextToken();
        return st.sval;
    }
    
    public Integer nextInt() {
        nextToken();
        return (int)st.nval;
    }
    
    private int nextToken() {
        int token = st.TT_EOF;
        try {
            token = st.nextToken();
        } catch (IOException e) {
        }
        return token;
    }
}

Measured memory_bytes: 20560
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++) arr[i]=0;
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int b;
            cin>>b;
            arr[b]++;
        }
    }
    int count=0;
    for(int i=1;i<=n;i++)
        if(arr[i]==0) count++;
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define Fd(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;

 int main()
 {
        char S[100];
        scanf("%s",(S+1));
        int n=strlen(S+1);

        if(n==(int)('z'-'a'+1))
        {
                bool c=true;
                F(i,1,n)
                {
                        if(S[i]!=(char)((int)'z'-i+1)) c=false;
                }

                if(c)
                {
                        printf("-1\n");
                        return 0;
                }
        }

        if(n<(int)('z'-'a'+1))
        {
                bool bl[30];
                F(i,0,26) bl[i]=false;
                F(i,1,n) bl[S[i]-'a']=true;

                printf("%s",(S+1));
                F(i,0,26)
                {
                        if(!bl[i])
                        {
                                printf("%c\n",(char)(i+'a'));
                                return 0; 
                        }
                }
                
        }

        char T[30];
        F(i,1,n) T[i]=S[i];

        next_permutation(S+1,S+1+n);
        
        F(i,1,n)
        {
                printf("%c",S[i]);
                if(S[i]!=T[i]) break;
        }

        printf("\n");
 }

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

int dp[5001][5001];

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n) {
    for (int j = i+1; j < n; ++j) {
      if (s[i] != s[j]) continue;
      if (i == j-dp[i][j]) continue;
      dp[i+1][j+1] = dp[i][j]+1;
      ans = max(ans, dp[i+1][j+1]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 96768
if __name__ == '__main__':
    S = str(input())

    AA = int(S[0:2])
    BB = int(S[2:4])

    if (1 <= AA <= 12) and (1 <= BB <= 12):
        answer = "AMBIGUOUS"
    elif (AA == 0 or AA >= 13) and (1 <= BB <= 12):
        answer = "YYMM"
    elif (1 <= AA <= 12) and (BB == 0 or BB >= 13):
        answer = "MMYY"
    else:
        answer = "NA"

    print(answer)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans = ans ^ a[i];
	}
	dump(ans == 0 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#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 UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<P> flowy(n);
	REP(i,n) {
		cin >> flowy[i].first >> flowy[i].second;
	}
	ll lb = 0, ub = 3 * INF * INF;
	while(ub - lb > 1) {
		ll mid = (ub + lb) / 2;
		ll cnt = 0;
		REP(i,n) {
			if(mid < flowy[i].first) continue;
			cnt += (mid - flowy[i].first) / flowy[i].second + 1;
		}
		if(cnt >= k) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 1792
//WA×1
#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int n;
    int a[100000];
    cin>>n;
    int ma=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ma<a[i]){ma=a[i];}
    }
    double half=ma/2.0;
    double diff=ma;
    int r=ma;
    for(int i=0;i<n;i++){
        if(a[i]!=ma){
        if(fabs(a[i]-half)<diff){diff=fabs(a[i]-half);r=a[i];}
        } 
    }
    cout<<ma<<" "<<r<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, x;
bool solve(int l, int r, vector<int> p, vector<int> q) {
	if (q.size() == 0) return false;
	int cnt = 0; bool ret = false;
	for (int i = 0; i < p.size(); i++) {
		if (p[i] == l - 1) {
			vector<int> p2 = p;
			p2.erase(p2.begin() + i);
			if (!solve(l - 1, r, q, p2)) ret = true;
			cnt++;
		}
		if (p[i] == r) {
			vector<int> p2 = p;
			p2.erase(p2.begin() + i);
			if (!solve(l, r + 1, q, p2)) ret = true;
			cnt++;
		}
	}
	if (cnt) return ret;
	return !solve(l, r, q, p);
}
int main() {
	cin >> n;
	while (n--) {
		vector<int> x(6), y;
		for (int i = 0; i < 6; i++) cin >> x[i];
		for (int i = 1; i <= 13; i++) {
			if (i != 7 && find(x.begin(), x.end(), i) == x.end()) y.push_back(i);
		}
		cout << (solve(7, 8, x, y) ? "yes" : "no") << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <cstdio>
#include <cctype>
#define reg register
#define int long long
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
signed main(void)
{
	int a,p;
	rd(a);rd(p);
	printf("%lld",(a*3+p)/2);
	return 0;
}


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

int main(){
  ll n; ll k;
  cin >> n >> k;
  ll a[n]; ll f[n];
  rep(i,n)  cin >> a[i];
  sort(a,a+n);  
  rep(i,n) cin >> f[i];
  ll l = -1, r = INF;
  while(r-l > 1) {
    ll m = (r+l)/2;
    ll t = 0;
    priority_queue<ll,vector<ll>,greater<ll>> que;
    rep(i,n) que.push(m/f[i]);
    bool can = true;
    ll z = k;
    rep(i,n) {
      ll p = que.top();
      que.pop();
      if(a[i] > p) z -= a[i] - p;
    }
    if(z >= 0) r = m;
    else l = m;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    long long ans;
    bool f;
    int st;
    if (s1[0] == s2[0])
    {
        ans = 3;
        st = 1;
        f = true;
    }
    else
    {
        ans = 6;
        st = 2;
        f = false;
    }
    for (int i = st; i < n; i++)
    {
        if (s1[i] == s2[i])
        {
            if (f)
            {
                (ans *= 2) %= mod;
            }
            else
            {
                f = true;
            }
        }
        else
        {
            i++;
            if (f)
            {
                (ans *= 2) %= mod;
                f = false;
            }
            else
            {
                (ans *= 3) %= mod;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int lengthx = x2 - x1, lengthy = y2 - y1;
    printf("%d %d %d %d", x2 - lengthy, y2 + lengthx, x1 - lengthy, y1 + lengthx);
}

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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pd pair<double, int>
#define pib pair<pi, bool>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 200001
#define MAXL 1000001
#define mod 1000000007

signed main()
{
  lli n, i = 0;
  cin >> n;
  lli precalc[1078];
  bool ok = false;
  while (1)
  {
    precalc[i] = pow(i, 5);
    if (precalc[i] == n)
    {
      cout << "0 -" << i << endl;
      ok = true;
    }
    if (i == 1077)
      break;
    i++;
  }
  if (!ok)
  {
    for (int i = 0; i < 1078; i++)
    {
      for (int j = 0; j <= i; j++)
      {
        if (precalc[i] < n)
        {
          if (precalc[i] + precalc[j] == n)
          {
            if (j != 0)
              j = j * -1;
            cout << i << " " << j << endl;
            ok = true;
            break;
          }
        }
        else
        {
          if (precalc[i] - precalc[j] == n)
          {
            cout << i << " " << j << endl;
            ok = true;
            break;
          }
        }
      }
      if (ok)
        break;
    }
  }
  return 0;
}

Measured memory_bytes: 4024
from sys import stdin
R, G, B, N = (int(i) for i in input().split())

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

for c in (R, G, B):
    for i in range(N + 1):
        if i + c <= N:
            dp[i+c] += dp[i]

print(dp[N])


Measured memory_bytes: 3060
$tb = {
  a: {0 => :x, 1 => :y},
  x: {1 => :z},
  y: {0 => :x},
  z: {0 => :w, 1 => :b},
  w: {0 => :b, 1 => :y},
  b: {0 => :y, 1 => :x},
}
def solve(routes)
  city = :a
  routes.each { |route|
    city = $tb[city][route]
    return false if city.nil?
  }
  city == :b
end
while (routes = gets.strip) != "#"
  puts solve(routes.chars.map(&:to_i)) ? "Yes" : "No"
end

Measured memory_bytes: 8724
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	ll n,k;
	cin >> n >> k;
	vector <pair<int,int>> ab(n);
	rep(i,n)
	{
		int a,b;
		cin >> a >> b;
		ab[i]= make_pair(a,b);
	}
	sort(ab.begin(),ab.end());
	ll count=0;
	rep(i,n)
	{
		count+=ab[i].second;
		if(count>=k)
		{
			cout<<ab[i].first<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
S = input()
T = input()

l = len(S)

for i in range(l):
    count = 0
    for j in range(l):
        if i+j >= l:
            if S[i+j-l] == T[j]:
                count += 1
            else:
                break
        else:
            if S[i+j] == T[j]:
                count += 1
            else:
                break

    if count == l:
        print('Yes')
        exit()

print('No')

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  rep(i, N) cin >> x[i];
  int _x = abs(x[0] - X);
  rep(i, N) _x = __gcd(_x, abs(x[i] - X));
  cout << _x << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18) + 1;
const ll mn = ll(1e9) + 7;

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

    ll n;
    cin >> n;
    vector<ll> an(n);
    rep(i,n) cin >> an[i];

    ll result = 0;
    ll temp = 0;
    rep(i,n-1){
        temp += an[i];
        temp %= mn;
        result += temp * an[i+1] % mn;
        result %= mn;
    }
    cout << result;
}

Measured memory_bytes: 4756
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
	dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))
print(dp[n-1])

Measured memory_bytes: 13928
import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math

S = input()
amari = [1, 10, 9, 12, 3, 4]
kurai = 0
hatena = []
base = 0
for i in range(len(S)):
	#print(S[len(S) - 1 - i])
	if S[len(S) - 1 - i] == '?':
		hatena.append(kurai)
	else:
		base += (int(S[len(S) - 1 - i])*amari[i % 6])
		base = base % 13
	kurai += 1

#print(base, hatena)
count13 = [0]*13
count13[base]+=1
for kurai in hatena:
	countnow = [0]*13
	for num in range(10):
		x = num * amari[kurai % 6]
		for i in range(13):
			y = (i + x) % 13
			countnow[y] += count13[i]
	for i in range(13):
		countnow[i] = countnow[i] % 1000000007
	count13 = copy.deepcopy(countnow)

print(count13[5])

Measured memory_bytes: 50336
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
#include <unordered_map>

using namespace std;

#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
//#define ll long long
using ll = long long;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
MIKUNO - 15/02/1999
*/
const int N = 1e5 + 5;
//	priority_queue <ll, vector<ll>, greater<ll> > q;
int n, m, k, cnt, rs, q;

int main()
{
	fast_input();
	cin >> n;
	vector<vector<int>> dp(n + 1, vector<int>(3, 0));
	for (int i = 1; i <= n; i++) {
		int ia, ib, ic;
		cin >> ia >> ib >> ic;
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + ia;
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + ib;
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + ic;
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

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

int main() {
  int N;
  cin >> N;
  bool flag = false;

  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      flag = true;
    }
  }
  if (flag)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <algorithm>
using namespace std;
#define reps(i,s,n) for(int (i) = (s); (i) < (n); ++(i))
#define rep(i,n) reps(i,0,n)
using ll = long long;
    
int main(){
     	int N;
	ll score = 0;
	cin >> N;
	vector<int> a(N,0);
	for(int i = 0; i < N; i++) cin >> a[i];

	for(int i = 0; i < N; i++){
		score += a[i];
	}

int ans1 = score;
int ans2 = score;
	if(score % 10 == 0){	
		sort(a.begin(),a.end());
		for(auto e : a){
			ans1 -= e;
			if(ans1 % 10 != 0){
				break;
			}	
		}

		for(auto e: a){
			if(e % 10 != 0){
				ans2 -= e;
				break;			
			}
		}
	}
//cout << "ans1:"<<ans1 <<endl;
//cout <<"ans2:" << ans2 << endl;
	
	if(ans1 >= ans2 || ans1 == 0) cout << ans1 <<endl;
	else cout<< ans2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c>b&&b>a)cout<<"Yes";
	else{
		bool e=0;
		for(int i=1;i<=d;i++){
			if(b>=c){
				c*=2;
				continue;
			}
			if(a>=b){
				b*=2;
				continue;
			}
			cout<<"Yes";
			e=1;
			break;
		}
		if(c>b&&b>a&&e==0)cout<<"Yes";
		else if(e==0)
		cout<<"No";
	}
	return 0;
}

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

int main() {
  string w;
  int n;
  cin >> n >>w;
  int ans=0;
  for(int i=0; i<n-2 ;i++){
    if(w.at(i)=='A' && w.at(i+1)=='B' && w.at(i+2)=='C'){
      ans++;
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n; cin >> n;
	VI a(n), b(n);
	REP(i,n) cin >> a[i];
	REP(i,n) cin >> b[i];
	vector<P> ap(n), bp(n);
	REP(i,n){
		ap[i].first=a[i];
		ap[i].second=i;
		bp[i].first=b[i];
		bp[i].second=i;
	}
	sort(ALL(ap));
	sort(ALL(bp));
	VI p(n);
	REP(i,n) p[ap[i].second]=bp[i].second;
	sort(ALL(a));
	sort(ALL(b));
	vector<bool> f(n,0); 
	int now=0; f[0]=1;
	while(1){
		now=p[now];
		if(f[now])
			break;
		f[now]=1;
	}
	bool rp=1;
	REP(i,n){
		if(!f[i]){
			rp=0;
			break;
		}
	}
	bool no=0, ok=0;
	REP(i,n){
		if(a[i]>b[i]){
			no=1;
			break;
		}
		if(i<n-1){
			if(a[i+1]<=b[i])
				ok=1;
		}
	}
	if(no||(rp&&!ok))
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 5760
def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    mid = 0
    diff = float("inf")
    total = sum(A)
    p = 0
    # print(total)
    for i in range(n):
        # print("i:",i, "total:", total, "p:", p, "diff:", diff)
        if abs(total-p) < diff:
            diff = abs(total - p)
            mid = i
        p += A[i]
        total -= A[i]
    front = A[:mid] 
    back =  A[mid:]
    print(abs(sum(front)-sum(back)))
resolve()

Measured memory_bytes: 31544
n = int(input())
aaa = list(map(int, input().split()))
aaa = [0] + aaa
for i in range(n // 2, 0, -1):
    b = 0
    j = i * 2
    while n >= j:
        b ^= aaa[j]
        j += i
    aaa[i] ^= b

ans = [i for i, b in enumerate(aaa) if b]
print(len(ans))
print(*ans)


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

int main() {
    string w_record;
    cin >> w_record;
    int count=0;
    for (int i=0; i<3; i++) {
        char day = w_record[i];
        if (day == 'R') {
            count++;
        }
    }
    char second_day = w_record[1];
    if (count == 2 && second_day == 'S') {
        count = 1;
    }
    cout << count << endl;
}

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

const int mod = 1e9 + 7;

int main() {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for (ll i = k; i <= n + 1; ++i) {
		ll Min = i * (i - 1) / 2;
		ll Max = n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2;
		ans += (Max - Min + 1) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#define N 2000001
 
int A[N],B[N],C[N];

main()
{

  
  int i,n,j,k=0;
  
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
   C[A[i]]++;
   
   if(k < A[i]){
      k = A[i];
   }
  }
  for(i = 1; i <= k; i++){
    C[i] = C[i] + C[i-1];
  }
  for(j = n-1; j >= 0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= n; i++){
    if(i!=n){
      printf("%d ",B[i]);
    }
    else {
      
      printf("%d\n",B[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 17892
H, W, K = map(int, input().split())

S = [list(map(int, input())) for _ in range(H)]
accS = [[0] * (W + 1) for _ in range(H + 1)]

for h in range(H):
    for w in range(W):
        accS[h + 1][w + 1] = accS[h + 1][w] + accS[h][w + 1] - accS[h][w] + S[h][w]

def isOk(L, left, right):
    for top, bot in zip(L, L[1:]):
        if accS[bot][right] - accS[bot][left] - accS[top][right] + accS[top][left] > K:
            return False
    return True

ans = 10**18

for mask in range(1 << H):
    L = [0] + [d + 1 for d in range(H - 1) if (mask & (1 << d)) > 0] + [H]

    cnt = len(L) - 2
    left = 0
    while left < W:
        right = left
        while right < W and isOk(L, left, right + 1):
            right += 1

        if left == right:
            cnt = 10**18
            break

        cnt += 1
        left = right

    ans = min(ans, cnt - 1)

print(ans)

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

  int N,M;
  vector<int> k,p;
  vector<vector<int>> s;

int check(int bit){
  rep(i,M){
    int count = 0;
    rep(j,k[i]){
      if(bit & ((1<<s[i][j])))count++;
    }
    //cout<<count<<endl;
    if(count%2 != p[i]) return 0;
  }
  return 1;
}



int main(){
  cin>>N>>M;
  k = p = vector<int>(M);
  s.resize(M);

  rep(i,M){
    cin>>k[i];
    s[i].resize(k[i]);

    rep(j,k[i]){
      cin>> s[i][j];
      s[i][j]--;
    }
  }
  rep(i,M) cin>>p[i];

  int ans = 0;
  for(int bit = 0; bit < (1<<N); bit++){
    ans += check(bit);
  }
  cout<<ans;
}


Measured memory_bytes: 256
import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == 'S':
        break
Q = collections.deque([[i, j, 0]])
sH = set()
sW = set()
while Q:
    h, w, dist = Q.popleft()
    sH.add(h)
    sW.add(w)
    if dist < K:
        for nh, nw in [[h - 1, w], [h + 1, w], [h, w - 1], [h, w + 1]]:
            if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '.':
                A[nh][nw] = '#'
                Q += [[nh, nw, dist + 1]]
print(1 + min([
    math.ceil(_ / K)
    for _ in (min(sH), H - 1 - max(sH), min(sW), W - 1 - max(sW))
]))


Measured memory_bytes: 11248
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());
		
		int []a = new int [n];
		int []b = new int [10000000];
		for(int i = 0 ;i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
			b[a[i]]++;
		}
		long ans1 = 0;
		
		for(int i = 0 ;i <=2000001 ; i++) {
			long temp = (long)b[i];
			ans1 += (long)(temp * (temp -1)) /2;
		}
		
		for(int i = 0 ; i < n ;i++) {
			long ans =(long)(ans1 - b[a[i]] + 1);
			System.out.println(ans);
		}
		
	}

}


Measured memory_bytes: 98596
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()

ans = 0
for i in range(1,N+1):
    ans += (N-i+1)*(N-i+2)//2
# 辺がない場合の答えを計算

for i in range(N-1):
    u,v = LI()
    if u > v:
        u,v = v,u
    ans -= u*(N-v+1)  # uとvを結ぶことで、どれくらい値が小さくなるかを考えている

print(ans)

Measured memory_bytes: 68644
#include<stdio.h>
#include<math.h>
int main(){
  double x[3],y[3],a,b,c,d,e,f;
  int n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<3;i++)scanf("%lf %lf",&x[i],&y[i]);
    a=2*(x[1]-x[0]);
    b=2*(y[1]-y[0]);
    c=2*(x[2]-x[0]);
    d=2*(y[2]-y[0]);
    e=x[1]*x[1]-x[0]*x[0]+y[1]*y[1]-y[0]*y[0];
    f=x[2]*x[2]-x[0]*x[0]+y[2]*y[2]-y[0]*y[0];
    x[0]=(e*d-b*f)/(a*d-b*c);
    y[0]=(a*f-c*e)/(a*d-b*c);
    printf("%.3f %.3f %.3f\n",x[0],y[0],hypot(x[0]-x[1],y[0]-y[1]));
  }
  return 0;
}

Measured memory_bytes: 676
<?php
  $ary = array();
  while (true) {
    $a_val = explode(" ", trim(fgets(STDIN)));
    if ($a_val[0] == "0" && $a_val[1] == "0") {
      break;
    }
    array_push($ary, $a_val);
  }
  $count = count($ary);
  foreach ($ary as $key => $val) {
    asort($val);
    print implode(" ", $val);
    if ($key+1 < $count) {
      print "\n";
    }
  }
?>

Measured memory_bytes: 7936
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>

#include <map>
 
using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e10,flag;

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	ans = b-a;
	if(ans%2==0) cout<<"Alice";
	else cout<<"Borys";
}



Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
dp=[[0,0]for _ in range(n)]
dp[0]=[a[0],-a[0]]
for i in range(1,n):
  dp[i][0]=max(dp[i-1][0]+a[i],dp[i-1][1]-a[i])
  dp[i][1]=max(dp[i-1][0]-a[i],dp[i-1][1]+a[i])
print(dp[n-1][0])

Measured memory_bytes: 30912
n = int(input())
mod = 26
x = 1
l = list()
while True:
    if n <= mod:
        for i in range(x):
            l.append(n%26)
            n = n//26
        break
    else:
        n -= mod
        mod *= 26
        x += 1
l.reverse()

l2 = list()
# if l.count(0) == x:
#     print("z"*x)
#     exit()
# for i in range(len(l)):
#     if l[i] == 0:
#         l[i-1] -= 1
#         l[i] = 26
if l.count(0) == x:
    print("z"*x)
    exit()
for i in range(x-1):
    l[i] += 1
for i in range(x-1,-1,-1):
    if l[i] == 0:
        l[i-1] -= 1
        l[i] = 26
for i in range(len(l)):
    l2.append(chr(l[i]+96))
print("".join(l2))

Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  int aa = 0,bb = 0,cc = 0,dd = 0,ee = 0 ,ff = 0,gg = 0,hh = 0;
  cin >> a >> b;
  vector<int> c= {1,3,5,7,8,10,12};
  vector<int> d= {4,6,9,11};
  vector<int> e= {2};
  
  for(int i = 0;i<c.size();i++){
    if(c.at(i) == a)
      aa  = 1;
    if(c.at(i) == b)
      bb = 1;
  }
  for(int i = 0;i<d.size();i++){
    if(d.at(i) == a)
      cc  = 1;
    if(d.at(i) == b)
      dd = 1;
  }
  for(int i = 0;i<e.size();i++){
    if(e.at(i) == a)
      ee  = 1;
    if(e.at(i) == b)
      ff = 1;
  }
  if(aa == 1 && bb == 1)
    cout << "Yes" << endl;
  else if(cc == 1 && dd == 1)
    cout << "Yes" << endl;
  else if(ee == 1 && ff == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

string t="ABC";

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int cnt=0;
	for(int i=0;i<n-2;i++)
	{
		bool flg=true;
		for(int j=0;j<3;j++)
			if(s[i+j]!=t[j])
				flg=false;
		if(flg)cnt++;
	}
	cout << cnt << endl;

	




}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  llint a,b;cin>>a>>b;
  //caricurate
  if((a<0)&&(0<b)){
    cout<<"Zero"<<endl;return 0;
  }else if(0<a){
    cout<<"Positive"<<endl;return 0;
  }else if((a==0)||(b==0)){
    cout<<"Zero"<<endl;return 0;
  }else if(b<0){
    if((b-a)%2==0){cout<<"Negative"<<endl;return 0;}
    else{cout<<"Positive"<<endl;return 0;}
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <math.h>
#include <map>
#include <bitset>
#include <queue>
#include <list>
#include <utility>

//#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<char>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };

int main()
{
	long x;
	cin >> x;
    long a = x / 500;
	long b = x - a*500;
	long c;
	if(b > 5)
	{
		c = b / 5;
	}
	int ans = a * 1000 + c * 5;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int n;
vector<int>e[maxn];
ll p[maxn];
int c[maxn];
ll f[maxn][2];

void gcd(ll a,ll b, ll& d,ll& x,ll& y){
  if(!b) {d=a;x=1;y=0;}
  else   {	gcd(b,a%b,d,y,x);	y-=a/b*x;}
}

ll inv(ll a,ll n)  {
  ll d,x,y;	gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}

void dfs1(int x, int fa) {
  int cc = 0;
  ll s = 1;
  for(int i=0;i<e[x].size();i++){
    int v = e[x][i];
    if(v==fa)continue;
    dfs1(v, x);
    cc += c[v];
    s = s * f[v][0] %mod;
    s = s * p[cc] % mod * inv(p[c[v]] * p[cc - c[v]]%mod, mod)%mod;
  }
  f[x][0] = s;
  c[x] = cc + 1;
}

ll ans[maxn];
void dfs2(int x, int fa) {
  int tt = c[x];
  ll all = f[x][0] * f[x][1] % mod * p[n-1] % mod * inv(p[tt - 1] * p[n-1-(tt-1)]%mod, mod) % mod;
  ans[x] = all;
  for(int i=0;i<e[x].size();i++){
    int v = e[x][i];
    if(v==fa)continue;
    ll tmp = f[v][0] * p[n-1] % mod * inv(p[c[v]] * p[n-1-c[v]]%mod, mod)%mod;
    f[v][1] = all * inv(tmp, mod)%mod;
    dfs2(v, x);
  };
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n;
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  p[0] = 1;
  for(int i=1;i<=n;i++) {
    p[i] = p[i-1] * i %mod;
  }
  dfs1(1, 0);
  f[1][1] = 1;
  dfs2(1, 0);
  for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 20980
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

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

  ll min_x = 0, max_x = W;
  ll min_y = 0, max_y = H;
  for (ll i = 0; i < N; i++)
  {
    ll x, y, a;
    cin >> x >> y >> a;

    switch (a)
    {
    case 1:
      min_x = max(min_x, x);
      break;
    case 2:
      max_x = min(max_x, x);
      break;
    case 3:
      min_y = max(min_y, y);
      break;
    case 4:
      max_y = min(max_y, y);
      break;
    
    default:
      break;
    }
  }
  cout << max(max_x - min_x, 0LL) * max(max_y - min_y, 0LL) << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> seconds(N, 0);
  for (int n = 1; n < N; ++n) {
    int C, S, F;
    cin >> C >> S >> F;
    for (int i = 0; i < n; ++i) {
      if (seconds[i] <= S) {
        seconds[i] = S;
      } else {
        int x = ceil(static_cast<float>(seconds[i] - S) / F);
        seconds[i] += (S + F*x - seconds[i]);
      }
      seconds[i] += C;
    }
  }
  for (auto s: seconds) cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> cnt(100100, -1);
  rep(i, n) cnt[a[i]]++;
  ll d = 0;
  rep(i, 100100) d += max(0, cnt[i]);
  if(d % 2) ++d;
  cout << n - d << endl;
}


Measured memory_bytes: 1024
#include<iostream>
 
using namespace std;
 
int main()
{
    for(double a;cin>>a,a>=0;){
        int n=(int)(a*16);
        if(n>(1<<12) || n!=a*16)   cout<<"NA"<<endl;
        else{
            for(int i=11;i>=0;i--){
                if(i==3)    cout<<'.';
                cout<<(bool)(n&(1<<i));
            }
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> div(101);
    div[1]=1;
    for(int i=2;i<=n;i++){
        int m=i;
        for(int j=2;j<=m;j++){
            if(m%j==0){
                div[j]++;
                m/=j;
                j--;
            }
            if(m==1) break;
        }
    }
    int a2=0,a4=0,a14=0,a24=0,a74=0;
    rep(i,101){
        int x=div[i];
        if(x>=2) a2++;
        if(x>=4) a4++;
        if(x>=14) a14++;
        if(x>=24) a24++;
        if(x>=74) a74++;
    }
    //cout<<a2<<" "<<a4<<" "<<a14<<" "<<a24<<" "<<a74<<endl;
    ll ans=0;
    ans+=a74;
    ans+=a14*(a4-1);
    ans+=a24*(a2-1);
    ans+=a4*(a4-1)*(a2-2)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define nn 436
#define ll long long
#define ull unsigned long long
ull has[nn][nn],cl[nn][nn];
ull hp=31,hpp[nn];
char buf[nn][nn];
int n;ll ans=0;
ull take(ll i,ll j)
{
	return has[i][j]+(has[i][0]-has[i][j]*hpp[j-0])*hpp[n-j];
}
ull took(ll i,ll j)
{
	return cl[i][j]+(cl[0][j]-cl[i][j]*hpp[i-0])*hpp[n-i];
}
int main()
{
	hpp[0]=1;for(int i=1;i<nn;i++) hpp[i]=hpp[i-1]*hp;
	cin>>n;
	for(int i=0;i<n;i++) scanf("%s",buf[i]);
	for(int i=0;i<n;i++)
	{
		for(int j=n-1;j>=0;j--)
			has[i][j]=has[i][j+1]*hp+buf[i][j]-'a';
	}
	for(int i=0;i<n;i++)
	{
		for(int j=n-1;j>=0;j--)
			cl[j][i]=cl[j+1][i]*hp+buf[j][i]-'a';
	}
	for(int A=0;A<n;A++)
	{
		for(int B=0;B<n;B++)
		{
			int flag=1;
			for(int i=0;i<n;i++)
			{
				int ci=(i+A)%n;int cj=(i+B)%n;
				flag&=(take(ci,cj)==took(ci,cj));
			}
			ans+=flag;
		}
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
 
using namespace std;
 
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define rep(i, x, n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define trav(a, x) for(auto& a: x)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007
#define endl '\n'
#define MAX 100002
#define pii pair<int, int>
#define pll pair<long long, long long>


typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vec;

int main(){
    fast_cin();
    string s, t;cin>>s>>t;
    s+=t[t.size()-1];
    if(s==t)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n; cin>>n;
	for(auto i=1;i<=9;++i){
		if(n%i==0){
			ll tmp=n/i;
			string s=to_string(tmp);
			if(s.size()==1){
				cout<<"Yes\n";
				return 0;
			}
		}
	}
	cout<<"No\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    x,y=input().split()
    if x<y:print("<")
    if x==y:print("=")
    if x>y:print(">")

main()

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(){
  int y1,m1,d1,y2,m2,d2;
  int month[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  for(int i=0;i<12;i++)
    month[i+1] += month[i];

  while(true){
    cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
    if (y1==-1)
      break;
    int day=0;
    day += d2-d1+month[m2-1]-month[m1-1]+(y2-y1)*365;
    if(m2<3)
      y2--;
    if(m1>2)
      y1++;
    day += y2/4-(y1-1)/4-y2/100+(y1-1)/100+y2/400-(y1-1)/400;
    cout << day << endl;
  }
  return 0;
}

Measured memory_bytes: 0