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

using namespace std;

char s[5][10];

int main ()
{
    for(int i = 0;i < 2;i++)
        cin >> s[i];
    if(s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[1][0] == s[0][2])
        cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>

using namespace std;

void trace(int A[],int N){
	int i;
	for (i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	putchar('\n');
}

void insertionSort(int A[], int N) {
	
	int i, j, v;

	for (i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 & A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main(){

	int N, i, j;
	int A[100];
	cin >> N;
	for (i = 0; i < N; i++) cin >> A[i];

	trace(A, N);
	insertionSort(A, N);

	return 0;
}

Measured memory_bytes: 1148
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[5][4][11]={0};
int b,f,r,v;
for(int i=0;i<n;i++)
{
cin>>b>>f>>r>>v;
a[b][f][r]+=v;
}
for(int i=1;i<=4;i++)
{
for(int j=1;j<=3;j++)
{
for(int k=1;k<=10;k++)
{
cout<<" "<<a[i][j][k];
}
cout<<endl;
}
if(i!=4)cout<<"####################"<<endl;
}
return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(ll)>
using namespace std;
#define All(v) (v).begin(),(v).end()
typedef long long ll;
const ll mod = 1000000007;
const ll inf = mod*mod;
const ll d5 = 114514;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1.0);
int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> V[d5];
    for(ll i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        a--;
        V[a].push_back(b);
    }
    priority_queue<ll> PQ;
    ll res = 0;
    for(ll i=0;i<m;i++){
        if(!V[i].empty()){
            for(auto it:V[i])PQ.push(it);
        }
        ll get=0;
        if(!PQ.empty()){
            get=PQ.top();
            PQ.pop();
        }
        res+=get;
    }
    cout<<res<<endl;
}

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

#define all(A) begin(A), end(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  string s;
  vector <string> endA, begB, ba;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    if (t.front() == 'B' and t.back() == 'A') {
      ba.push_back(t);
    } else if (t.back() == 'A') {
      endA.push_back(t);
    } else if (t.front() == 'B') {
      begB.push_back(t);
    } else {
      s += t;
    }
  }
  if (not endA.empty()) s += endA.back(), endA.pop_back();
  while (not ba.empty()) s += ba.back(), ba.pop_back();
  if (not begB.empty()) s += begB.back(), begB.pop_back();
  while (not endA.empty() and not begB.empty()) {
    s += endA.back();
    s += begB.back();
    endA.pop_back();
    begB.pop_back();
  }
  while (not endA.empty()) s += endA.back(), endA.pop_back();
  while (not begB.empty()) s += begB.back(), begB.pop_back();
  int ans = 0;
  for (int i = 1; i < sz(s); i++) {
    if (s[i - 1] == 'A' and s[i] == 'B') ans++;
  }
  cout << ans << endl;
  return (0);
}


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

int main()
{
    int x;
    std::cin >> x;

    int ans = 0;
    int y = x % 100;
    int n = x / 100;

    for (int i = 0; i < n; i++) {
        if (y >= 5) y-=5;
        else if (y >= 4) y-=4;
        else if (y >= 3) y-=3;
        else if (y >= 2) y-=2;
        else if (y >= 1) y-=1;
    }

    if (y == 0) {
        ans = 1;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {
	
	ll N, M;
	cin >> N >> M;

	ll like[100] = {};

	repn(i, N) {
		ll k;
		cin >> k;
		repn(j, k) {
			ll a;
			cin >> a;
			like[a]++;
		}
	}

	ll ans = 0;

	repn(i, M) {
		if (like[i] == N) { ans++; }
	}

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<ll> positive,negative,zero;
    rep(i,n){
        ll x;
        cin >> x;
        if(x<0){negative.pb(x);}
        if(x==0){zero.pb(x);}
        if(x>0){positive.pb(x);}
    }
    reverse(negative.begin(),negative.end());
    int get_nonzero_num = k-zero.size();
    ll ans = INF;
    if(get_nonzero_num<=0){
        cout << 0;
    }
    else{
        rep(i,get_nonzero_num+1){
            int neg_num = i;
            int pos_num = get_nonzero_num-i;
            ll neg_max = 0;
            ll pos_max = 0;
            if(negative.size() >= i && positive.size() >= get_nonzero_num-i){
                if(i==0){
                    ans = min(ans,positive[get_nonzero_num-1]);
                }
                else if(i==k){
                    ans = min(ans,abs(negative[get_nonzero_num-1]));
                }
                else{
                    ll neg_max = abs(negative[neg_num-1]);
                    ll pos_max = positive[pos_num-1];
                    ans = min(ans,neg_max + pos_max + min(neg_max,pos_max));
                }
            }
        }
            cout << ans;
    }
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int m;
template<class T, size_t n> class squarematrix{
public:
	vector<vector<T>> a;
	constexpr squarematrix() : a(vector<vector<T>>(n, vector<T>(n, 0))){}
	constexpr squarematrix(vector<vector<T>> v) : a(v){}
	constexpr squarematrix &set_diag(T t){
		for(size_t i=0; i<n; ++i)
			for(size_t j=0; j<n; ++j)
				a[i][j] = (i == j ? t : 0);
		return *this;
	}
	constexpr squarematrix operator*(const squarematrix rhs) const {
		return squarematrix(*this) *= rhs;
	}
	constexpr squarematrix &operator*=(const squarematrix rhs){
		squarematrix<T, n> tmp(a);
		for(size_t i=0; i<n; ++i)
			for(size_t j=0; j<n; ++j){
				a[i][j] = 0;
				for(size_t k=0; k<n; ++k){
					a[i][j] += tmp.a[i][k] * rhs.a[k][j] % m;
					a[i][j] %= m;
				}
			}
		return *this;
	}
	constexpr T at(const size_t j, const size_t k){
		return a[j][k];
	}
};
template<class T> T pwr(T a, T e, Int n){
	while(n > 0){
		if(n & 1) e *= a;
		a *= a;
		n >>= 1;
	}
	return e;
}
Int modpow(Int x, Int y, Int m){
	Int res = 1;
	while(y > 0){
		if(y & 1){
			res *= x;
			res %= m;
		}
		y >>= 1;
		x *= x;
		x %= m;
	}
	return res;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	Int l, a, b; cin >> l >> a >> b >> m;
	vector<Int> v;
	for(Int i=0; i<19; ++i){
		Int t = 1;
		for(Int j=0; j<i; ++j) t *= 10;
		Int u = max<Int>(0, min((t - a + b - 1) / b, l));
		v.push_back(u);
	}
//	for(size_t i=0; i<v.size(); ++i)
//		cout << i << " " << v[i] << "\n";
	squarematrix<Int, 3> A; A.set_diag(1);
	squarematrix<Int, 3> E; E.set_diag(1);
	for(Int i=0; i<18; ++i){
		Int x = v[i], y = v[i+1];
		squarematrix<Int, 3> B = pwr(squarematrix<Int, 3>(vector<vector<Int>>({{modpow(10, i+1, m), 1, 0}, {0, 1, b}, {0, 0, 1}})), E, y-x);
		A = B * A;
/*		cout << i << "\n";
		for(int i=0; i<3; ++i)
			for(int j=0; j<3; ++j)
				cout << B.at(i, j) << " \n"[j==2];
*/	}
	Int ans = (A.at(0, 1) % m * (a % m) % m + A.at(0, 2)) % m;
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;
long long INF = 1000000009;
int main()
{
	int n;
	cin >> n;
	vector<int> L(n);
	for (int i = 0; i < n; i++) cin >> L[i];
	sort(L.rbegin(), L.rend());
	int tmp = L.at(0);
	int sum = 0;
	for (int i = 0; i < n; i++) sum += L.at(i);
	sum -= L.at(0);
	if (tmp < sum) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	vector<int>a1, a2, a4;

	for (int i = 0; i < n; i++) {
		int tmp = a[i];
		if (tmp%4==0)a4.push_back(a[i]);
		else if (tmp%2==0)a2.push_back(a[i]);
		else a1.push_back(a[i]);
	}
	if(a2.size() == 0)	cout << (a4.size() + 1 >= a1.size() ? "Yes" : "No") << endl;
	else cout << (a4.size() >= a1.size() ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
    ll H,W;
    cin >> H>>W;
    vector<vector<char>> G(H,vector<char>(W));
    ll cnt = 0;
    rep(i,H){
        rep(j,W){
            cin >>G[i][j];
            if(G[i][j] == '.'){
                cnt++;
            }
        }
    }

    vector<vector<ll>> dist(H,vector<ll>(W,-1));
    queue<pair<ll,ll>> que;
    dist[0][0] = 0;
    ll min;
    que.push(make_pair(0,0));
    bool flag = 0;
    while(!que.empty()){
        pair<ll,ll> v = que.front();
        que.pop();
        if(v.first == H-1 && v.second == W-1){
            flag = 1;
            min = dist[v.first][v.second]+1;
            break;
        }
        rep(dir,4){
            ll ny = v.first+dy[dir];
            ll nx = v.second+dx[dir];
            if(!In_map(ny,nx,H,W)) continue;
            if(G[ny][nx] == '#') continue;
            if(dist[ny][nx] != -1) continue;
            dist[ny][nx] = dist[v.first][v.second]+1;
            que.push(make_pair(ny,nx));
        }
    }
    ll ans;
    if(flag == 0){
        ans = -1;
    }else{
        ans = cnt-min;
    }
       
    cout << ans << endl;



    return 0;
    

}

Measured memory_bytes: 3596
#include <stdio.h>
int main(void)
{
	int W, H, x, y, r;

	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if ((-100 <= x) && (-100 <= y) && (x <= 100) && (y <= 100) && (0 < W) && (0 < H) && (0 < r) && (W <= 100) && (H <= 100) && (r <= 100) && (r <= x) && (x <= W - r) && (r <= y) && (y <= H - r))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

string str;
int i, ok1;
int k, t, j, lg, n, m, rez;
char a[1001][1001];
int mn=9999999;
int mat[1001][1001];

struct coada
{
    int x, y, dist;
}C[1000001], aux;

int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int inc, fin, x, y;
int main()
{
    cin>>n>>m;
    cin.get();
    for (i=1;i<=n;i++)
        cin.getline(a[i], 1001);

    for (i=0;i<=n+1;i++)
        mat[i][0]=mat[i][m+1]=-1;
    for (j=0;j<=m+1;j++)
        mat[0][j]=mat[n+1][j]=-1;
    inc=-1;
    fin=0;
    int nr=0;
    for (i=1;i<=n;i++)
        for (j=0;j<=m;j++)
        {
            if (a[i][j]=='#')
            {
                C[nr].x=i;
                C[nr].y=j+1;
                C[nr].dist=1;
                mat[i][j+1]=1;
                nr++;
            }
        }
    fin=nr-1;
    while (fin>inc)
    {
        inc++;
        aux=C[inc];
        for (k=0;k<4;k++)
        {
            x=aux.x+dx[k];
            y=aux.y+dy[k];
            if (mat[x][y]==0)
            {
                mat[x][y]=mat[aux.x][aux.y]+1;
                fin++;
                C[fin].x=x;
                C[fin].y=y;
                C[fin].dist=mat[x][y];
            }

        }
    }
    int mx=0;
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
        if (mx<mat[i][j]) mx=mat[i][j];
    cout<<mx-1<<'\n';
    return 0;
}


Measured memory_bytes: 16896
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n,k,s;
cin>>n>>k>>s;
vector<ll>ans;
for(ll i=0;i<k;i++)
{
    ans.pb(s);
}
ll x=1e9;
if(x==s)
{
    x--;
}
for(ll i=k;i<n;i++)
{
 ans.pb(x);
}
for(ll i=0;i<n;i++)
{
    cout<<ans[i]<<" ";
}
return 0;
}


Measured memory_bytes: 2292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype (i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype (i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype (i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,
mod=1000000007;
const double pi=3.1415926535897932,
eps=1e-6;
int n,m,a[2005],b[2005],f[2005][2005];
int main()
{
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%d",a+i);
    rep(i,1,m) scanf("%d",b+i);
    rep(i,1,n) rep(j,1,m){
        f[i][j]=((ll)f[i-1][j]+f[i][j-1]-f[i-1][j-1]+mod)%mod;
        if(a[i]==b[j])f[i][j]=((ll)f[i][j]+f[i-1][j-1]+1+mod)%mod;
    }
    printf("%d",(f[n][m]+1)%mod);
    return 0;
}

Measured memory_bytes: 16000
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_3_C&lang=jp
# Count

from functools import reduce
from collections import deque
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    l  = list ( map(int,input().split()))

    for i in range(int(input())):
        (n1,n2,a) = map(int,input().split())    
        count = len(list(filter(lambda x : x == a,l[n1:n2])))
        print (count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6380
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
typedef long long ll;
const int MOD = 1000000007;
#define PI 3.1415
using namespace std;

int main() {
	double r;
	cin >> r;
	cout << 2 * r * PI << endl;
	return 0;
}


Measured memory_bytes: 3788
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int MOD = (int)1e9 + 7;

int n,m,h[101],hnum[101],dh[101];///h记录每一列高度 dh记录离散化后的各不相同的高度 hnum记录h对应dh中的位置，即第几高的高度
long long dp[101][101];///记录第i列第n块高度往上的方案数

int pow_(long long x,int y) {///快速幂求 x的y次方
    long long ans = 1;
    if(y > 0) {
        while(y) {
            if(y % 2)ans = ans * x % MOD;
            x = x * x % MOD;
            y /= 2;
        }
    }
    return ans;
}

int main() {
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++) {
        scanf("%d",&h[i]);
        dh[++ m] = h[i];///先把高度存到dh数组 下标从1开始，方便后面dp
    }
    sort(dh + 1,dh + m + 1);///dh数组排序
    m = unique(dh + 1,dh + m + 1) - dh - 1;///dh数组离散化去掉重复的高度 m是不相同的高度数
    for(int i = 1;i <= n;i ++) {
        hnum[i] = lower_bound(dh + 1,dh + m + 1,h[i]) - dh;///每一列高度在dh数组中对应的位置
    }
    dp[0][0]=1;///初始化 当第0列有1个无连续相同的方案
    for(int i = 1;i <= n;i ++) {///对每一列每个高度段进行更新 更新过程为从下往上
        (dp[i][0] += dp[i - 1][0] * 2 % MOD) %= MOD;///无连续相同方案  加上前i - 1列无连续相同方案数*2 因为可以是与前一列对应位置同色或者异色一共两种方案
        for(int j = hnum[i] + 1;j <= hnum[i - 1];j ++)///如果前一列比这一列高，高出的部分也存着接触部分无连续相同的方案 但是可能会重复加上上一步的方案数所以下面更新高出的部分时会避免
            (dp[i][0] += dp[i - 1][j] * 2 % MOD) %= MOD;
        int d = pow_(2,h[i] - h[i - 1]);///比前一列高出部分的涂色方案数，如果比前一列低 d就等于1
        for(int j = 1;j <= min(hnum[i - 1],hnum[i]);j ++) {
            dp[i][j] = dp[i - 1][j] * d % MOD;///有连续相同颜色的方案数 已经分析过接触部分的颜色一定是定下的 所以这一列接触部分有连续相同部分的方案数由高出部分的变化决定 即 乘上d
        }
        for(int j = hnum[i - 1] + 1;j <= hnum[i];j ++) {///更新比前一列高出的部分 j从上一列的高度加1的下标开始
            if(j > 1)(dp[i][j] = dp[i - 1][0] * (pow_(2,dh[j] - dh[j - 1]) - 1) % MOD * 2 % MOD * pow_(2,h[i] - dh[j]) % MOD) %= MOD;
            ///一般情况 前i - 1列无连续方案 * （第j块高度变化方案 -1表示去掉无连续相同方案) * 2 * 剩下几块高度的变化方案数
            else (dp[1][1] = dp[0][0] * (pow_(2,dh[1]) - 2) % MOD * pow_(2,h[i] - dh[1]) % MOD) %= MOD;
            ///第一列的第一块高度 记录随意变化方案数 -2表示除去dp[i][0]已经记录过的无连续相同方案 勿重复记录
        }
    }
    long long ans = 0;
    for(int i = 0;i <= hnum[n];i++)
        (ans += dp[n][i]) %= MOD;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 384
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 min = Integer.parseInt(sc.next());
        int count = 1;
        for(int i = 1; i < n; i++){
            int p = Integer.parseInt(sc.next());
            if(p <= min){
                count++;
                min = p;
            }
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 50556
mod = 10**9 + 7
N = int(input())
S = list(input())
al = [chr(ord("a") + i ) for i in range(26)]
cntAl = [ S.count(chr(ord("a") + i )) for i in range(26)]
ans = 1
for a in cntAl:
    if a != 0:ans *= (a+1)%mod
print((ans-1)%mod)

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

int main() {
    int N, temp;
    cin >> N;

    temp = N;

    int f = 0;
    while(temp != 0){
        f += temp % 10;
        temp /= 10;
    }

    if((N % f) == 0) cout << "Yes" << endl;
    else             cout << "No"  << endl;
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

//Node treeMinimum(Node x){


//}

//Node treeSearch(Node u, int k){


//}

//Node treeSuccessor(Node x){


//}

//void treeDelete(Node z){
//Node y; // node to be deleted
//Node x; // child of y



//}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->left!=NIL) preorder(u->left);
  if(u->right!=NIL) preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    //if ( com[0] == 'f' ){
    //scanf("%d", &x);
    //Node t = treeSearch(root, x);
    //if ( t != NIL ) printf("yes\n");
    //else printf("no\n");
    //}
  if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  //else if ( com[0] == 'd' ){
  //  scanf("%d", &x);
  //  treeDelete(treeSearch(root, x));
  //}
  }
  return 0;
}

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

ll n;
set<ll> a;

int main(){
	cin >> n;

	for(ll i=0, temp; i<n; i++){
		cin >> temp;
		if(a.count(temp)){
			a.erase(temp);
		}
		else{
			a.insert(temp);
		}
	}

	cout << a.size() << endl;
}


Measured memory_bytes: 4864
while 1:
	m,f,r = map(int,input().split())
	if m == -1 and f == -1 and r == -1:
		break
	if m == -1 or f == -1:
		print('F')
	elif m+f>=80:
		print('A')
	elif m+f>=65 and m+f<80:
		print('B')
	elif m+f>=50 and m+f<65:
		print('C')
	elif m+f>=30 and m+f<50:
		if r>=50:
			print('C')
		else:
			print('D')
	else:
		print('F')


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x, t;
  cin >> x >> t;
  if (x > t) {
  	cout << x - t << endl;
  }else {
  	cout << 0 << "\n";
  }
}

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

int main() {
int A, B, C;
cin >> A >> B >> C;

int n = 0;
if(A == B) n++;
if(B == C) n++;
if(C == A) n++;

if(n==1) cout << "Yes" << endl;
else cout << "No"<< endl;

return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 1
cnt = [0 for _ in range(max(a)+1)]
cnt0 = 0
for i in range(n):
  if a[i] == 0:
    ans *= 3 - cnt0
    cnt[a[i]] += 1
    cnt0 += 1
  else:
    ans = ans * cnt[a[i]-1] % mod
    cnt[a[i]] += 1
    cnt[a[i]-1] -= 1
print(ans%mod)

Measured memory_bytes: 14056
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

void swap(int& x, int& y) {
    x ^= y; y ^= x; x ^= y;
}

int main(void) {
    map<char, int> m;
    m.insert(make_pair('A', 1)); m.insert(make_pair('B', 2)); m.insert(make_pair('C', 3));
    int cup[4]; memset(cup, 0, sizeof(cup));
    cup[1] = 1;
    char a, b;
    while(scanf("%c,%c", &a, &b) != EOF) {
        swap(cup[m[a]], cup[m[b]]);
    }
    char alph = 'A';
    for(int r = 1; r < 4; r++, alph++) {
        if(cup[r]) cout << alph << endl;
    }
    return(0);
}

Measured memory_bytes: 1188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		for (int i = 1; i <= n; i++) {
			int i2 = (int) (i * 1.08);
			if (i2 == n) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(":(");
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  long long N;
  cin >> N;

  const int MOD = 1000000007;

  if (N == 1)
    cout << 0 << endl;
  else if (N == 2)
    cout << 2 << endl;
  else
  {
    long long ans = 1;
    long long ans2 = 1;
    long long ans3 = 1;

    rep(i, N)
    {
      ans *= 10;
      ans %= MOD;

      ans2 *= 9;
      ans2 %= MOD;

      ans3 *= 8;
      ans3 %= MOD;
    }

    ans += ans3;
    ans %= MOD;

    ans -= ans2;
    if (ans < 0)
      ans += MOD;
    ans -= ans2;
    if (ans < 0)
      ans += MOD;

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
using namespace std;
using ll = long long;

void insertionSort(vector<int> A,int N){
    int j, i, v;
    rep(i, 1, N){
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        rep(k, 0, N-1) cout << A[k] << " ";
        cout << A[N-1] << endl;
    }
    return;
}

int main() {
    int n; cin >> n;
    V v(n);
    rep(i, 0, n) cin >> v[i];
    rep(i, 0, n-1) cout << v[i] << " ";
    cout << v[n-1] << endl;
    insertionSort(v, n);
}



Measured memory_bytes: 3172
N, M = map(int, input().split())
array = sorted([list(map(int, input().split()))
                for i in range(M)], key=lambda x: x[1])

# print(array)
count = 0
position = -float("inf")
for i in range(M):
    if array[i][0] < position:
        pass
    else:
        position = array[i][1]
        count += 1
print(count)


Measured memory_bytes: 65240
#include <iostream>
#include <algorithm>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

struct City{
  int idx, p, y;
  
  bool operator < (const City &c) const {
    if (p == c.p) return y < c.y;
    
    return p < c.p;
  }
};

int N, M;
City c[100005];
pair<int, int> x[100005];

int main(void) {
    scanf("%d %d", &N, &M);
    
    REP(i, 0, M) {
      int P, Y;
      scanf("%d %d", &P, &Y);
      c[i].idx = i;
      c[i].p = P;
      c[i].y = Y;
    }

    sort(c, c+M);
    
    int k = 1;
    REP(i, 0, M) {
      x[c[i].idx] = make_pair(c[i].p, k);
      
      if ( c[i].p == c[i+1].p ) k++;
      else k = 1;
    }
    REP(i, 0, M) printf("%06d%06d\n", x[i].first, x[i].second);

    return 0;
}


Measured memory_bytes: 3456
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
import std.math, core.bitop;
 
auto solve(string s_)
{
    immutable N = s_.to!int();
    immutable xs = readln.split.map!(to!int).array();
    immutable L = readln.chomp.to!int();
    immutable Q = readln.chomp.to!int();
    auto ab = new int[2][Q];
    foreach(ref v;ab) v = readln.split.map!(to!int).array();
    immutable D = (xs[$-1]-xs[0]+L-1)/L;
    immutable M = bsr(D)+((D&D-1)?0:1);
    auto ld = new int[][](N+1,M);
    for(int i=0,j=0; i<N; ++i)
    {
        while(j<i && (xs[i]-xs[j])>L) ld[j++][0]=i-1;
        if(i+1==N) while(j<N) ld[j++][0]=i;
    }
    ld[N-1][0]=N;
    ld[N][]=N;
    foreach(i;1..M) foreach(j;0..N) ld[j][i]=ld[ld[j][i-1]][i-1];
    int[] r; r.reserve(Q);
    foreach(ref v;ab)
    {
        auto a=v[0]-1,b=v[1]-1;
        if(a>b) swap(a,b);
        int d=0;
        while(a<b)
        {
            int lo=0, hi=M;
            while(lo+1<hi)
            {
                immutable m = (lo+hi)/2;
                if(ld[a][m]<=b) lo=m;
                else            hi=m;
            }
            d+=1<<lo;
            a=ld[a][lo];
        }
        r~=d;
    }
    return r.map!(to!string).join("\n");
}

void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 19756
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int D; cin >> D;
	int C[26];
	int S[370][26];
	REP(i, 26)cin >> C[i];
	REP(i, D)REP(j, 26)cin >> S[i][j];
	REP(i, D) {
		cout << 1 << endl;
	}

	return 0;
}



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


int main() {
    int n;
    cin >> n;
    if(n <= 999){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


N = int(input())

uf = UnionFind(N)

xy = []
min_y = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y, i))
    min_y.append(y)

xy.sort()

min_y = N+1

for i in range(N-1):
    x, y, a = xy[i]
    x1, y1, b = xy[i+1]
    min_y = min(min_y, y)
    if min_y != N - i:
        uf.union(a, b)

for i in range(N):
    print(uf.get_size(i))


Measured memory_bytes: 125160
import bisect

n, q = [int(x) for x in input().split()]
s = input()

index = []
for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        index.append(i)

for i in range(q):
    l, r = [int(x) for x in input().split()]
    print(bisect.bisect_right(index, r-2) - bisect.bisect_left(index, l-1))


Measured memory_bytes: 5748
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 100010;

int n;
ll a[MAXN], b[MAXN];

int main() {
    scanf( "%d", &n );
    for( int i = 1; i <= n; ++i )
        scanf( "%lld%lld", a+i, b+i );
    ll ans = 0;
    for( int i = n; i >= 1; --i ) {
        a[i] += ans;
        if( a[i] % b[i] == 0 ) continue;
        ll t = a[i]/b[i] + 1;
        ans += b[i]*t - a[i];
    }
    printf( "%lld\n", ans );
    return 0;
}


Measured memory_bytes: 1792
import sys, math,os
from io import BytesIO, IOBase
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(Decimal, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7
from decimal import Decimal


def main():

    a,b=mdata()
    out(int(a*b))


if __name__ == '__main__':
    main()

Measured memory_bytes: 10076
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
long long const inf = 1e18, linf = 2e9, mod = 1e9+7;
int const mxn = 4e5+10;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}




int main(){
	int n , m ; 
	cin>>n>>m;
	cout<<(n*(n-1))/2 + (m*(m-1))/2;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [0] * 45
for i in c:
    e = bin(i)[2:]
    for j in range(len(e)):
        d[j] += 1 if e[-j-1] == "1" else 0
e = 0
for i in range(len(d)-1, -1, -1):
    if 2 ** i + e <= b:
        if d[i] <= len(c) // 2:
            e += 2 ** i
f = 0
for i in range(len(c)):
    f += e ^ c[i]
print(f)


Measured memory_bytes: 14620
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int a[105];
set<pair<pair<int, int>, int>> s;
int main() {
  IOS;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i] &&
            a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
          // cout << i << ' ' << j << ' ' << k << endl;
          s.insert({{i, j}, k});
        }
      }
    }
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 13680
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn zalgo(s: &[char]) -> Vec<usize> {
    let len = s.len();
    let mut res = vec![0; len];
    res[0] = len;
    let mut i = 1;
    let mut j = 0;
    while i < len {
        while i + j < len && s[j] == s[i + j] {
            j += 1;
        }
        res[i] = j;
        if j == 0 {
            i += 1;
            continue;
        }
        let mut k = 1;
        while i + k < len && k + res[k] < j {
            res[i + k] = res[k];
            k += 1;
        }
        i += k;
        j -= k;
    }
    res
}

fn solve() {
    input! {
        n: usize,
        s: Chars
    };

    let mut res = 0;
    for i in 0..n {
        let lv = zalgo(&s[i..]);
        for j in 0..n - i {
            let l = lv[j].min(j);
            res = res.max(l);
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2360
#include <stdio.h>
#include <stdlib.h>

int fibonacci(int );

static int F[100] = {};

int main() {
  int number;

  scanf("%d",&number);
  

  printf("%d\n",fibonacci(number));
  
}

int fibonacci(int n) {
  if(n==0 || n==1) return F[n] = 1;
  if(F[n] != 0) return F[n];
  return F[n] = fibonacci(n-2) + fibonacci(n-1);
}



Measured memory_bytes: 2112
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from operator import or_


class SegmentTree:
    def __init__(self, orig, func, unit):
        _len = len(orig)
        self.func = func
        self.size = 1 << (_len - 1).bit_length()
        self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
        self.unit = unit

        for i in range(self.size - 1, 0, -1):
            self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])

    def update(self, i, v):
        i += self.size
        self.tree[i] = v
        while i:
            i //= 2
            self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

    def find(self, l, r):
        l += self.size
        r += self.size
        ret = self.unit
        while l < r:
            if l & 1:
                ret = self.func(ret, self.tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.func(ret, self.tree[r])
            l //= 2
            r //= 2
        return ret


n = readline()
s = readline()
q = int(readline())
li = [1 << ord(x) - 97 for x in s[:-1]]
seg = SegmentTree(li, or_, 0)
ans = []
for _ in range(q):
    f, x, y = readline().split()
    x = int(x)
    if f == '1':
        seg.update(x - 1, 1 << ord(y) - 97)
    else:
        y = int(y)
        z = seg.find(x - 1, y)
        cnt = bin(z).count('1')
        ans.append(cnt)
print(*ans)


Measured memory_bytes: 48768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e15;
int mod = 1e9+7;

//最小値取得
class SegmentTree{
public:
	int n = 1;
	vector<int> seg[2];
	//m要素のセグメントツリー作成
	void init(int m){
		while(n < m)n *= 2;
		rep(i,2)seg[i].resize(2*n);
		rep(i,2)fill(all(seg[i]), inf);
	}
	//kの値をxに変更
	void update(int t, int k, int x){
		k += n-1;
		seg[t][k] = x;
		while(k > 0){
			k = (k-1)/2;
			seg[t][k] = min(seg[t][k*2+1], seg[t][k*2+2]);
		}
	}
	int calc(int t, int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return inf;
		if(a <= l && r <= b)return seg[t][k];
		int vl = calc(t, a, b, k*2+1, l, (l+r)/2);
		int vr = calc(t, a, b, k*2+2, (l+r)/2, r);
		return min(vl, vr);
	}
	//[a,b)の最小値を求める
	int get(int t, int a, int b){return calc(t, a, b, 0, 0, n);}
};

int a[200004], dp[2][200004];
int n, q, x, y;
SegmentTree seg;
int solve(){
	int ans = inf, mem = 0;
	rrep(i,q){
		int vl = seg.get(0, 0, a[i])+a[i];
		int vr = seg.get(1, a[i], n)-a[i];
		int res = min(vl, vr)-llabs(a[i]-a[i-1]);
		seg.update(0, a[i-1], res-a[i-1]);
		seg.update(1, a[i-1], res+a[i-1]);
		mem += llabs(a[i]-a[i-1]);
	}
	rep(i,n)chmin(ans, seg.get(0, i, i+1)+i);
	rep(i,n)chmin(ans, seg.get(1, i, i+1)-i);
	return ans+mem;
}

signed main(){
	scanf("%lld%lld%lld%lld", &n, &q, &x, &y);
	rrep(i,q)scanf("%lld", &a[i]), a[i]--;
	x--;y--;
	
	int ans = inf;
	a[0] = y;
	seg.init(n+1);
	seg.update(0, x, -x);
	seg.update(1, x, x);
	chmin(ans, solve());
	
	/*a[0] = x;
	seg.init(n+1);
	seg.update(0, y, -y);
	seg.update(1, y, y);
	chmin(ans, solve());*/
	
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

#define int long long

const int   mod = 1e9 + 7;
const int   N   = 5e3 + 1;

void add(int &a,int b)  {
	a += b;
	if(a >= mod)a -= mod;
	if(a <  0)  a += mod;
}
int qpow(int a,int exp) {
	int ans = 1;
	while (exp) {
		if(exp & 1) ans = ans * a % mod;
		a = a * a % mod;  exp >>= 1;
	}
	return  ans;
}

int Fac[N], Inv[N];

int n, c, nCh[N];
vector<int> g[N];

void dfs(int u,int p)   {
	nCh[u] = 1;
	for(int v : g[u])
		if (v != p) {
			dfs(v,u);
			nCh[u] += nCh[v];
		}
}
int Cen(int u,int p)    {
	for(int v : g[u])
		if (v != p && nCh[v] > n / 2)
			return Cen(v,u);
	for(int v : g[u])
		if (v != p && nCh[v] == n - nCh[v]) {
			cout << Fac[n / 2] * Fac[n / 2] % mod;
			exit(0);
		}
	return u;
}

int f[N], r[N];

signed main()   {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	
	Fac[0] = 1;
	for(int i = 1 ; i <= n ; ++i)   Fac[i] = Fac[i - 1] * i % mod;
	Inv[n] = qpow(Fac[n],mod - 2);
	for(int i = n - 1 ; ~i ; --i)   Inv[i] = Inv[i + 1] * (i + 1) % mod;
		
	for(int i = 1 ; i < n ; ++i)    {
		int x, y;   cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	
	dfs(1,0);   c = Cen(1,0);
	dfs(c,0);
	vector<int> vec;
	for(int v : g[c])   vec.push_back(nCh[v]);
	
	int cur = 0;
	f[0] = 1;
	for(int x : vec)    {
		cur += x;
		for(int i = 0 ; i <= cur ; ++i) {
			r[i] = f[i];
			f[i] = 0;
			for(int j = 0 ; j <= min(i,x) ; ++j)    {
				int choose = Fac[x] * Fac[x] % mod;
				    choose = choose * Inv[j] % mod;
				    choose = choose * Inv[x - j] % mod;
				    choose = choose * Inv[x - j] % mod;
				add(f[i],r[i - j] * choose % mod);
			}
		}
	}
	
	int ans = 0, mul = 1;
	
	for(int i = 0 ; i < n ; ++i, mul = -mul)
		add(ans,mul * f[i] * Fac[n - i] % mod);
	
	cout << ans << endl;
}

Measured memory_bytes: 896
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1];
	auto S = rs;
	if(S[A] == '-' && S[0..A].isNumeric && S[$-B..$].isNumeric) {
		writeln("Yes");
	} else writeln("No");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
package main

/*
全探索.
*/

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func solve(k int, ms []int) bool {
	return solveK(k, 0, 0, ms)
}

func solveK(k, sum, idx int, ms []int) bool {
	if sum == k {
		return true
	}
	if idx >= len(ms) {
		return false
	}
	return solveK(k, sum+ms[idx], idx+1, ms) || solveK(k, sum, idx+1, ms)
}

func isAssembleK(k int, ms []int) bool {
	for i, m := range ms {
		if k == m {
			return true
		}
		if m < k {
			if isAssembleK(k-m, ms[i+1:len(ms)]) {
				return true
			}
		}
	}
	return false
}

// func solve(k int, ms []int) bool {
// 	for i := range ms {
// 		if isAssembleK(k, ms[i:len(ms)]) {
// 			return true
// 		}
// 	}
// 	return false
// }
//
// func isAssembleK(k int, ms []int) bool {
// 	for i, m := range ms {
// 		if k == m {
// 			return true
// 		}
// 		if m < k {
// 			if isAssembleK(k-m, ms[i+1:len(ms)]) {
// 				return true
// 			}
// 		}
// 	}
// 	return false
// }

func main() {
	scanner := makeScanner(8192)
	eGetInt(scanner)
	ms := eGetInts(scanner)
	eGetInt(scanner)
	qs := eGetInts(scanner)
	for _, q := range qs {
		if solve(q, ms) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(max int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), max)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	var ints []int
	for _, f := range fields {
		ints = append(ints, eAtoi(f))
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = " "
	}
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}
func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}



Measured memory_bytes: 1152
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

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

const int INF = 1001001001;

struct Data {
	int y, x, c;
	Data(){}
	Data(pii p, int c) : y(p.first), x(p.second), c(c) {}
};

int main()
{
	int w, h;
	while(scanf("%d%d", &w, &h), w){
		vector<pii> S(1), G(1);
		vector<pii> pos[5];
		rep(i, h){
			char tmp[1024];
			scanf("%s", tmp);
			rep(j, w){
				if(tmp[j] == 'S')
					S[0] = pii(i, j);
				if(tmp[j] == 'G')
					G[0] = pii(i, j);
				if(isdigit(tmp[j]))
					pos[tmp[j]-'1'].push_back(pii(i, j));
			}
		}
		
		int B = INF;
		int Bi = -1;
		rep(i, 5){
			vector<Data> cand(1, Data(S[0], 0));
			rep(j, 5){
				vector<pii>& next = j<4 ? pos[(i+j+1)%5] : G;
				vector<Data> tmp(next.size());
				rep(k, next.size()){
					tmp[k].y = next[k].first;
					tmp[k].x = next[k].second;
					tmp[k].c = INF;
					rep(l, cand.size())
						tmp[k].c = min(tmp[k].c, abs(tmp[k].y-cand[l].y)+abs(tmp[k].x-cand[l].x)+cand[l].c);
				}
				cand = tmp;
			}
			if(cand[0].c < B){
				B = cand[0].c;
				Bi = i;
			}
		}
		if(Bi == -1)
			puts("NA");
		else
			printf("%d %d\n", Bi+1, B);
	}
}

Measured memory_bytes: 1136
def is_sorted(lst):
    for i in range(len(lst) - 1):
        if lst[i] > lst[i + 1]:
            return False
    return True

N = int(input())
p = list(map(int, input().split()))

yes  = False
for i in range(N):
    for j in range(i, N):
        tmp = p[j]
        p[j] = p[i]
        p[i] = tmp
        if is_sorted(p):
            yes = True
            break
        tmp = p[j]
        p[j] = p[i]
        p[i] = tmp
    if yes:
        break

if yes:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include<iostream>
#define ll long long
using namespace std;
int main() {
	int n,x;
	while(1) {
		int i,j,k;
		int count=0;
		cin >> n >> x;
		if(n==0&&x==0) break;
		for(i=1;i<=n;i++) {
			for(j=i+1;j<=n;j++) {
				for(k=j+1;k<=n;k++) {
					if(i+j+k==x) count++;
				}
			}
		}
		cout << count << endl;
	}
	
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

istream& operator >> (istream&is,P<int,int>&p){is >> p.first >> p.second;return is;}

int main(){
  int n,m; cin >> n >> m;
  vector<P<int,int>>v(m); cin >> v;
  sort(v.begin(), v.end());
  int pre = -1;
  int ans = 0;
  for(auto e:v){
    if(e.first > pre){
      pre = e.second-1;
      ans++;
    } else {
      if(e.second <= pre){
	pre = e.second-1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4012