akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

mint dp[41][1<<5][1<<7][1<<5] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,X,Y,Z;
    cin >> N >> X >> Y >> Z;
    dp[0][1<<(X-1)][0][0] = 1;
    for(int i=0;i<N;i++){
        for(int A=0;A<(1<<X);A++) for(int B=0;B<(1<<Y);B++) for(int C=0;C<(1<<Z);C++){
            for(int k=1;k<=10;k++){
/*                if(k>=8){
                    dp[i+1][1<<(X-1)][0][0] += dp[i][A][B][C];
                    continue;
                }*/
                if(C>>(k-1)&1) continue;
                int nA = A>>k,nB = B>>k,nC = C>>k;
                if(B>>(k-1)&1){
                    nC |= 1<<(Z-1);
                }
                if(A>>(k-1)&1){
                    nB |= 1<<(Y-1);
                }
                nA |= 1<<(X-1);
                dp[i+1][nA][nB][nC] += dp[i][A][B][C];
            }
        }
    }
    mint ans = 1;
    for(int i=0;i<N;i++) ans *= 10;
    for(int A=0;A<(1<<X);A++) for(int B=0;B<(1<<Y);B++) for(int C=0;C<(1<<Z);C++) ans -= dp[N][A][B][C];
    cout << ans << "\n";
}

Measured memory_bytes: 45636
n, d = map(int, input().split())
X = []
for i in range(n):
    x = list(map(int, input().split()))
    X.append(x)

c = 0
for i in range(n):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            s += (X[i][k] - X[j][k])**2
        s = s**0.5

        if s.is_integer():
            c += 1
print(c)

Measured memory_bytes: 38384
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#define rep(i,n) for(int i(0);i<n;i++)
#define chmin(x,y) x=min(x,y)
const int INF = 1001001001;

using namespace std;
int main(){
    int n, m, l;
    cin >> n >> m >> l;

    vector<vector<int>> dist(n,vector<int>(n,INF));
    rep(i,n) dist[i][i] = 0;
    rep(i,m){
        int a, b, c;
        cin >> a >> b >> c;
        --a;--b;
        dist[a][b] = dist[b][a] = c;
    }

    rep(k,n)rep(j,n)rep(i,n) chmin(dist[i][j],dist[i][k]+dist[k][j]);

    vector<vector<int>> dist2(n,vector<int>(n,INF));
    rep(i,n)rep(j,n){
        if(dist[i][j] <= l) dist2[i][j] = 1;
    }

    rep(k,n)rep(j,n)rep(i,n) chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);

    int q;
    cin >> q;
    rep(i,q){
        int s,t;
        cin >> s >> t;
        --s;--t;
        int ans = dist2[s][t] - 1;
        if(dist2[s][t] == INF) ans = -1;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
int main(){
    long X,Y;
    cin>>X>>Y;
    long A=X;
    int ans=0;
    while(A<=Y){
        ans++;
        A*=2;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

int main(void)
{
    string a, b;
    cin >> a >> b;
    if (a.length() > b.length())
        cout << "GREATER" << endl;
    else if (b.length() > a.length())
        cout << "LESS" << endl;
    else
    {
        int i = 0;
        while (i < a.length() && a[i] == b[i])
            i++;
        if (i == a.length())
            cout << "EQUAL" << endl;
        else if (a[i] > b[i])
            cout << "GREATER" << endl;
        else if (b[i] > a[i])
            cout << "LESS" << endl;
    }
}


Measured memory_bytes: 3496
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

unsigned long long dp[301][301];
unsigned long long yoko[301], tate[301];
const int cm = 1 << 12;
char cn[cm], * ci = cn, ct;

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


	fread(cn, 1, cm, stdin);
	int N = 0, M = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
	while ((ct = *ci++) >= '0') M = M * 10 + ct - '0';

	int xm[301][4], xM[301][4];
	rep1(i, N) {
		xm[i][1] = N;
		xm[i][2] = N;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l = 0, r = 0;
		while ((ct = *ci++) >= '0') l = l * 10 + ct - '0';
		while ((ct = *ci++) >= '0') r = r * 10 + ct - '0';
		int x = *ci++ - '0';
		ci++;
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	yoko[0] = 1;
	tate[0] = 1;
	int mj = 0;
	int mk = 0;
	rep1(i, N) {
		for (int k = i - 1; k >= 0; k--) {
			dp[k][i] = yoko[k] + tate[k];
			if (dp[k][i] >= mod) dp[k][i] -= mod;
		}
		for (int k = i; k >= 0; k--) {
			yoko[k] += dp[k][i];
			if (yoko[k] >= mod) yoko[k] -= mod;
			tate[i] += dp[k][i];
		}
		tate[i] %= mod;

		for (int j = i; j > max(xm[i][2], mj - 1); j--) {
			if (yoko[j]) {
				for (int k = i; k >= max(j, mk); k--) {
					tate[k] += mod - dp[j][k];
					if (tate[k] >= mod) tate[k] -= mod;
					dp[j][k] = 0;
				}
				yoko[j] = 0;
			}
		}
		for (int k = i; k > max(xm[i][1], mk - 1); k--) {
			if (tate[k]) {
				for (int j = min(i, k); j >= mj; j--) {
					yoko[j] += mod - dp[j][k];
					if (yoko[j] >= mod) yoko[j] -= mod;
					dp[j][k] = 0;
				}
				tate[k] = 0;
			}
		}
		for (int k = xM[i][2]; k >= mk; k--) {
			if (tate[k]) {
				for (int j = min(i, k); j >= mj; j--) {
					yoko[j] += mod - dp[j][k];
					if (yoko[j] >= mod) yoko[j] -= mod;
					dp[j][k] = 0;
				}
				tate[k] = 0;
			}
		}
		for (int j = xM[i][3]; j >= mj; j--) {
			if (yoko[j]) {
				for (int k = i; k >= max(j, mk); k--) {
					tate[k] += mod - dp[j][k];
					if (tate[k] >= mod) tate[k] -= mod;
					dp[j][k] = 0;
				}
				yoko[j] = 0;
			}
		}
		if (mj <= xM[i][3]) mj = xM[i][3] + 1;
		if (mk <= xM[i][2]) mk = xM[i][2] + 1;
	}

	ll kotae = 0;
	for (int j = mj; j <= N; j++) kotae += yoko[j];
	printf("%lld ", kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <sstream>  // istringstream
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

// qiita
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{   
    int N;
    cin >> N;
    int A[N];
    for(int i=0; i<N; ++i) cin >> A[i];

    // 余りをとる問題
    // 計算途中で余りをとっても変わらない

    // 記録
    int memo[100000+10] = {0};
    for(int i=0; i<N; ++i){
        memo[A[i]]++;
    }

    bool flag = true;
    if(N%2 != 0){ // 奇数人の場合
        if(memo[0] != 1){ // 0が必ず一人いる
            flag = false;
        }
        for(int i=2; i<N; i+=2){
            if(memo[i] != 2){ // 各偶数が2人ずつ
                flag = false;
            }
        }
    }
    else{ // 偶数人の場合
        for(int i=1; i<N/2; i+=2){
            if(memo[i] != 2){ // 各奇数が2人ずつ
                flag = false;
            }
        }
    }

    long long ans = modpow(2, N/2, 1000000000+7);
    if(!flag) ans = 0;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int ConvertToInt(string s){
    int res = 0;
    int x = 1;
    for(int i = s.size() - 1; i >= 0; i--){
        res += x * (int(s[i]) - 48);
        x *= 10;
    }
    return res;
}

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

    if(ConvertToInt(s.substr(0, 4)) <= 2019 && ConvertToInt(s.substr(5, 2)) <= 4 &&  ConvertToInt(s.substr(8, 2)) <= 30)
        cout << "Heisei";
    else cout << "TBD";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n;
  string s;
  cin >> n >> s;
  int a[100010];
  rep(a0, 2) rep(a1, 2)
  {
    fill(a, a + n, -1);
    a[0] = a0, a[1] = a1;
    bool can = true;
    rep(i, n)
    {
      int j1 = (i - 1 + n) % n, j2 = (i + 1) % n;
      assert(a[j1] != -1 || a[j2] != -1);
      if (a[j1] != -1 && a[j2] != -1)
      {
        if ((a[j1] == a[j2]) ^ (s[i] == 'o') ^ (a[i] == 0) ^ 1)
        {
          can = false;
          break;
        }
      }
      else if (a[j1] == -1)
      {
        a[j1] = a[j2] ^ (a[i] == 0) ^ (s[i] == 'o');
      }
      else if (a[j2] == -1)
      {
        a[j2] = a[j1] ^ (a[i] == 0) ^ (s[i] == 'o');
      }
    }
    if (can)
    {
      rep(i, n) cout << (a[i] == 0 ? 'S' : 'W');
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 976
#include <iostream>
using namespace std;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)

template<int MOD> struct MInt {
  long long val;
  constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator-() const { return MInt(-val); }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
  friend istream& operator>>(istream& os, MInt& n) { os>>n.val; return os; }
};
constexpr int MOD = 1e9+7;
using mint = MInt<MOD>;

string K;
int D;
constexpr int MAX_N = 10000, MAX_D = 100;
mint dp[MAX_N+1][MAX_D][2];

int main() {
  cin >> K >> D;

  dp[K.size()][0][0] = dp[K.size()][0][1] = 1;

  rrep(i, K.size()-1) rep(r, D) rep(lower, 2) {
    int n = K[i] - '0';
    rep(j, (lower ? 9 : n) + 1)
      dp[i][r][lower] += dp[i+1][(r+j)%D][lower||(j<n)];
  }

  cout << dp[0][0][false]-1 << endl;

  return 0;
}


Measured memory_bytes: 15872
n = int(input())
link = [[] for _ in range(n)]
for i in range(n):
    s=input()
    for j in range(n):
        if s[j]=="1":
            link[i].append(j)

from collections import deque
Q = deque()
Q.append([0,0])
visited=[-1]*n
visited[0]=0 # 0 or 1
while Q:
    now,color = Q.popleft()
    for nxt in link[now]:
        if visited[nxt]!=-1:
            if visited[nxt] == (color+1)%2:
                continue
            else:
                print(-1)
                exit()
        visited[nxt]=(color+1)%2
        Q.append([nxt,(color+1)%2])

ans=0
for i in range(n):
    Q = deque()
    Q.append([i,0])
    visited=[-1]*n
    visited[i]=1
    while Q:
        now,cnt = Q.popleft()
        for nxt in link[now]:
            if visited[nxt]!=-1:
                continue
            visited[nxt]=cnt+1
            Q.append([nxt,cnt+1])
    mx = max(visited)
    ans=max(ans,mx)

print(ans+1)

Measured memory_bytes: 41836
N, M = map(int, input().split())
adj = {}
for i in range(N):
    adj[i + 1] = []
for i in range(M):
    v1, v2 = map(int, input().split())
    adj[v1].append(v2)
    adj[v2].append(v1)

visited = {1}
parent = {1: None}
frontier = [1]
while frontier:
    nxt = []
    for u in frontier:
        for v in adj[u]:
            if v not in visited:
                parent[v] = u
                nxt.append(v)
                visited.add(v)
    frontier = nxt

if len(visited) < N:
    print("No")
else:
    print("Yes")
    for i in range(2, N + 1):
        print(parent[i])




Measured memory_bytes: 57000
#include<bits/stdc++.h>
using namespace std;
int a[1000000+500];
int main(){
	int n;
	cin>>n;
	int cnt=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(!i){
			cnt+=a[i];
		}
		else if(a[i]>a[i-1])
			cnt+=a[i]-a[i-1];
	}
	cout<<cnt<<endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

vector<vi> g;

int solve(int u1, int u2, int m) {
	vi dp(n, INF);
	queue<int> q;
	q.push(u1);
	if (u1 != u2) q.push(u2);
	dp[u1] = dp[u2] = 0;
	int res = n;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		if (dp[u] > m) break;
		res--;
		for (int v : g[u]) {
			if (chmin(dp[v], dp[u] + 1)) q.push(v);
		}
	}
	return res;
}

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	g.resize(n);
	REP(i, n-1) {
		int u, v;
		cin >> u >> v; u--; v--;
		g[u].eb(v);
		g[v].eb(u);
	}
	int ans = n;
	if (m % 2) {
		REP(u, n)for (int v : g[u]) {
			ans = min(ans, solve(u, v, m/2));
		}
	} else {
		REP(u, n) ans = min(ans, solve(u, u, m/2));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

constexpr int bm = 2500;
ll BIT[50][bm];
int zero[50];
//priority_queue<ll> PQ;
const int AS = 25000;
class saidai_tekitou_heap {
public:
	int HS = 0;
	const ll IM = -8e18;
	ll dat[AS * 2 + 2];
	saidai_tekitou_heap() : dat() {
		dat[0] = -IM;
		rep1(i, AS * 2 + 1) dat[i] = IM;
	}
	void push(ll v) {
		int p = ++HS;
		while (v > dat[p >> 1]) dat[p] = dat[p >> 1], p >>= 1;
		dat[p] = v;
	}
	ll pop() {
		if (HS == 1) {
			HS = 0;
			return dat[1];
		}
		ll ret = dat[1];
		ll v = dat[HS];
		dat[HS--] = IM;
		int j = 2 + (dat[2] < dat[3]);
		while (v < dat[j]) {
			dat[j >> 1] = dat[j];
			j <<= 1;
			j += dat[j] < dat[j + 1];
		}
		dat[j >> 1] = v;
		return ret;
	}
} PQ;
inline ll query(int A, int gin) {
	ll kotae = 0;
	while (gin < bm) {
		kotae = max(BIT[A][gin], kotae);
		gin += gin & -gin;
	}
	return kotae;
}
inline void query2(int A, int gin, ll ti) {
	int tmp = gin;
	while (gin < bm) {
		if (BIT[A][gin] >= ti) return;
		gin += gin & -gin;
	}
	gin = tmp;
	while (gin > 0) {
		if (BIT[A][gin] >= ti) break;
		BIT[A][gin] = ti;
		gin -= gin & -gin;
	}
	PQ.push(ti << 18 | A << 12 | tmp);
}

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


	int N, M, S;
	cin >> N >> M >> S;
	if (S >= 2460) S = 2460;

	vector<ll> E[50];
	rep(i, M) {
		int u, v, a;
		ll b;
		cin >> u >> v >> a >> b;
		u--;
		v--;
		b = a << 8 | b << 16;
		E[u].pb(v | b);
		E[v].pb(u | b);
	}
	int C[50], D[50];
	rep(i, N) {
		cin >> C[i] >> D[i];
	}

	query2(0, S + 1, 4e12);
	ll zenbu = 0;
	ll owari = (1ll << N) - 1;

	while (PQ.HS) {
		auto p = PQ.pop();
		ll ti = p >> 18;
		int i = p >> 12 & 63;
		int gin = p & 4095;
		if (ti < query(i, gin)) continue;

		ll ti2 = ti - D[i];
		int gin2 = gin + C[i];
		if (gin2 > 2460) gin2 = 2460;
		query2(i, gin2, ti2);

		for (auto pp : E[i]) {
			int to = pp & 255;
			ti2 = ti - (pp >> 16);
			gin2 = gin - (pp >> 8 & 255);
			if (gin2 > 0) query2(to, gin2, ti2);
		}
		zenbu |= 1ll << i;
		if (zenbu == owari) break;
	}

	for (int i = 1; i < N; i++) {
		co(ll(4e12 - query(i, 1)));
	}



	Would you please return 0;
}

Measured memory_bytes: 4992
import sys
from bisect import bisect_left
sys.setrecursionlimit(10**7)
def input():return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    to = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    
    ans = [0] * N
    dp = []
    def dfs(now, pre):
        a = A[now]
        idx = bisect_left(dp, a)

        if idx == len(dp):
            old = -1
            dp.append(a)
        else:
            old = dp[idx]
            dp[idx] = a
        
        ans[now] = len(dp)

        
        for nv in to[now]:
            if nv != pre:
                dfs(nv, now)
        

        if old == -1:
            dp.pop()
        else:
            dp[idx] = old

    
    dfs(0, -1)

    print(*ans, sep="\n")
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 282732
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int):
    for i in range(N, 1000):
        if len(set(str(i))) == 1:
            return i


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    result = solve(N)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5140
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
	static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9  
	public static void main(String[] args) throws Exception{
		hayami saori = new hayami();
		int k = saori.saori_hayami();
		String s = saori.nextHayami();
		if(s.length() <= k) {
			System.out.println(s);
		} else {
			String str[] = s.split("");
			for(int i = 0;i < k;i++){
				System.out.print(str[i]);
			}
			System.out.println("...");
		}
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}


Measured memory_bytes: 32712
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,Q;
    cin >> N >> Q;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    ll X[100010];
    rep(i,0,Q) cin >> X[i];
    vector<ll> pos;
    ll sum[100010] = {};
    rep(i,0,N) sum[i+1] = sum[i] + A[i];
    ll sum_odd[100010] = {}, sum_even[100010] = {};
    rep(i,0,N){
        if(i % 2 == 0){
            sum_even[i+1] += sum_even[i] + A[i];
            sum_odd[i+1] += sum_odd[i];
        }else{
            sum_even[i+1] += sum_even[i];
            sum_odd[i+1] += sum_odd[i] + A[i];
        }
    }

    rrep(i,N-2,0){
        ll diff = N - i - 1;
        ll p1 = i, p2 = p1 - diff;
        if(p2 < 0) break;
        ll v = (A[p2] + A[p1])/2 + 1;
        pos.push_back(v); 
    }
    reverse(pos.begin(), pos.end());
    // printa(pos, pos.size());
    ll sz = pos.size();
    rep(i,0,Q){
        ll p = upper_bound(pos.begin(), pos.end(), X[i]) - pos.begin();
        ll num = sz - p + 1;
        ll taka = sum[N] - sum[N-num];
        ll s = N - num*2 - 1;
        // print(taka);
        if(s < 0){
            print(taka);
        }else{
            if(s % 2 == 0){
                taka += sum_even[s+1];
            }else{
                taka += sum_odd[s+1];
            }
            print(taka);

        }


    }


    

}

Measured memory_bytes: 6136
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	A=list(map(int,input().split()))
	S=[0]
	for i in range(n):
		S.append(S[i]+A[i])
	S.sort()
	S.append(10**18)
	cnt=0
	ans=0
	for i in range(n+1):
		if S[i]==S[i+1]:
			cnt+=1
		else:
			ans+=cnt*(cnt+1)//2
			cnt=0
	print(ans)






if __name__ == "__main__":
	main()


Measured memory_bytes: 21960
WMAX = 10 ** 4 + 1
N = int(input())
W1 = [int(w) for w in input().split()]
W2 = sorted(W1)
W3 = {}
mn1 = min(W1)
V = [False] * N

for i, w in enumerate(W2):  W3[w] = i

cost = 0
for i in range(N):
    if V[i]: continue
    cur = i
    S = 0
    N2 = 0
    mn2 = WMAX
    while True:
        V[cur] = True
        S += W1[cur]
        mn2 = min(mn2, W1[cur])
        N2 += 1
        cur = W3[W1[cur]]
        if V[cur]: break
    cost += min(mn2 * (N2 - 2) + S, mn2 + S + (1 + N2) * mn1)

print(cost)


Measured memory_bytes: 5720
#include<iostream>
#include<vector>
using namespace std;
int main() {
    string s;
    int k;
    cin >> s;
    cin >> k;
    string res;
    for (char c = 'a'; c <= 'z' && k > 0; ++c) {
        vector<int> v;
        for (int i = 0; i < s.size(); ++i) if (s[i] == c) v.push_back(i);
        if (v.size() == 0) {
            continue;
        } else if (k == 1) {
            cout << c << endl;
            return 0;
        }
        res = c;
        --k;
        int j = 1;
        while (k > 0) {
            char min = 'z';
            bool flg = false;
            vector<int> _v;
            for (auto itr = v.begin(); itr != v.end(); ++itr) {
                if (*itr+j >= s.size()) continue;
                flg = true;
                char _c = s[*itr+j];
                if (_c < min) {
                    min = _c;
                    _v = {*itr};
                } else if (_c == min) {
                    _v.push_back(*itr);
                }
            }
            if (flg) {
                res += min;
                ++j;
                --k;
                v = _v;
            } else {
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
int main(void) {
	ll n,k;
	cin >> n >> k;
	map<ll, ll>num;
	ll a, b;
	for (ll i = 0;i < n;i++) {
		cin >> a >> b;
		num[a] += b;
	}
	ll sum = 0;
	for (auto itr = num.begin();;++itr) {
		sum += itr->second;
		if (sum >= k) {
			cout << itr->first << endl;
			return 0;
		}
		if (itr == num.end()) {
			cout << itr->first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n;
    cin >> n;
    vector<string>sn(n);
    for(int i = 0; i < n; i++){
        cin >> sn.at(i);
    }
    set<string> s;
    for(int i = 0; i < n; i++){
        s.insert(sn.at(i));
    }
    cout << s.size() << endl;
    solve();
    return 0;
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    double ans = 0;
    REP(i,N){
        double x; string S; cin >> x >> S;
        if(S=="JPY"){
            ans += x;
        }else{
            ans += x*380000;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int N, a[100009], b[100009];
long long S, ans;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d %d", &a[i], &b[i]), S += a[i];
for (int i=1; i<=N; i++)
    if (a[i] > b[i])
    {
        long long curr = a[i] - b[i] + S - a[i];
        if (curr > ans)
            ans = curr;
    }
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int a, b, c;

int main() {

	cin >> a >> b >> c;

	if ((a != b && a != c && b == c) || (b != c && a != b && a == c) || (c != b && a != c && b == a))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
# 8重for
# N,A,B,C = 5,100,90,80
# L = [98,40,30,21,80]
N,A,B,C = map(int, input().split())
L = [int(input()) for _ in range(N)]
ans = float('inf')
for i1 in range(4):
    for i2 in range(4):
        for i3 in range(4):
            for i4 in range(4):
                for i5 in range(4):
                    for i6 in range(4):
                        for i7 in range(4):
                            for i8 in range(4):
                                p = [i1,i2,i3,i4,i5,i6,i7,i8]
                                take = [[] for _ in range(4)] # [A,B,C,使わない]
                                for i in range(N):
                                    take[p[i]].append(L[i])
                                a,b,c = take[0],take[1],take[2]
                                if len(a)*len(b)*len(c)==0:
                                    continue 
                                cost = (len(a)+len(b)+len(c)-3)*10
                                cost += abs(sum(a)-A)+abs(sum(b)-B)+abs(sum(c)-C)
                                ans = min(ans, cost)
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		int[] dp = new int[N];
		dp[0] = 0;
		dp[1] = Math.abs(arr[0] - arr[1]);

		for (int i = 2; i < N; i++) {
			dp[i] = Integer.MAX_VALUE;

			for (int j = 1; j <= K; j++) {
				if (i - j < 0)
					break;
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(arr[i] - arr[i-j]));
			}
		}

		System.out.println(dp[N-1]);
	}
}

Measured memory_bytes: 50456
#include <iostream>
using namespace std;
int main()
{
	int n; cin>>n;
	
    int c0=0,c1=0,c2=0,c3=0;
    
    while(n--){
    	string s; cin>>s;
    	
    	if(s=="AC"){
    		c0++;
    	}else if(s=="WA"){
    		c1++;
    	}else if(s=="TLE"){
    		c2++;
    	}else{
    		c3++;
    	}
    }
    
    cout<<"AC x "<<c0<<"\n";
    cout<<"WA x "<<c1<<"\n";
    cout<<"TLE x "<<c2<<"\n";
    cout<<"RE x "<<c3<<"\n";
    
    
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
using namespace std;
int a[10000];
int main(){
	int i, x = 1000001, y = -1000001,  n;
	long long z=0;
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> a[i];
		if (x > a[i]){
			x = a[i];
		}
		if (y < a[i]){
			y = a[i];
		}
		z += a[i];

	}
	cout << x << ' ' << y << ' ' << z << endl;
	return 0;
}


Measured memory_bytes: 3124
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s; cin >> s;
    int n = (int)s.size();
    vector<int> a(n + 1, 0);
    int po = 1;
    map<int, int> mp;
    mp[0] ++;
    for(int i = 0; i < n; ++ i) {
        a[i + 1] = (a[i] + (s[n - 1 - i] - '0') * po) % 2019;
        //cerr << a[i + 1] << " " << po << endl;
        mp[a[i + 1]] ++;
        po *= 10;
        po %= 2019;
    }
    int ans = 0;
    for(int i = 1; i < 2019; ++ i) {
        ans += mp[i] * (mp[i] - 1) / 2;
    }
    ans += mp[0] * (mp[0] - 1) / 2;
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    ll N;
    cin >> N;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];
    ll ans = v[1];
    for(int i = 0; i < N; i++){
        ans = gcd(v[i], ans);
    }
    cout << ans << endl;
}


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

using namespace std;

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	vector<vector<long long>> kankei(n+1);
	vector<long long> dis(n+1,-1);

	for(long long i=0;i<n;i++){
		long long u,k;
		cin>>u>>k;
		for(long long j=0;j<k;j++){
			long long hoge;
			cin>>hoge;
			kankei.at(u).push_back(hoge);
		}
	}

	queue<long long> que;
	que.push(1);
	dis.at(1)=0;

	while(!que.empty()){
		long long now=que.front();
		que.pop();

		for(auto a:kankei.at(now)){
			if(dis.at(a)!=-1) continue;
			que.push(a);
			dis.at(a)=dis.at(now)+1;
		}
	}

	for(long long i=1;i<=n;i++){
		cout<<i<<" "<<dis.at(i)<<endl;
	}

	return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// a,bに同じ数が含まれてたら(a,b)にその数が入ることは確定する
// aの任意の2要素をswapしても答えに影響はない
// 大きい数字から決めていくってのは確定っぽい 今見てる数字は今まで見た数字たちと同じ行/列にしか入れない
// その候補のマス数をかけていけば普通に答えになりそう

int h, w, a[1010], b[1010], aa[1001001], bb[1001001], def, res = 1;
set<int> row, col;

signed main() {
	cin >> h >> w;
	rep(i,h) cin >> a[i];
	rep(i,w) cin >> b[i];
	sort(a,a+h), reverse(a,a+h), sort(b,b+w), reverse(b,b+w);
	memset(aa,-1,sizeof(aa)), memset(bb,-1,sizeof(bb));
	rep(i,h) {
		if (aa[a[i]]==-1) aa[a[i]] = i;
		else return cout << 0 << endl, 0;
	}
	rep(i,w) {
		if (bb[b[i]]==-1) bb[b[i]] = i;
		else return cout << 0 << endl, 0;
	}
	for (int x=h*w; x>=1; x--) {
		if (aa[x]!=-1 && bb[x]!=-1) row.insert(aa[x]), col.insert(bb[x]), def++;
		else if (aa[x]!=-1) row.insert(aa[x]), (res *= (ll)col.size()) %= mod, def++;
		else if (bb[x]!=-1) col.insert(bb[x]), (res *= (ll)row.size()) %= mod, def++;
		else if (aa[x]==-1 && bb[x]==-1) (res *= max(0ll, (ll)row.size()*(ll)col.size() - def)) %= mod, def++;
	}
	cout << res << endl;
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
string s, t;
int cnt1[26];
int cnt2[26];
int main() {
	int i;	
	cin >> s >> t;
	rep(i, s.length()) cnt1[s[i] - 'a']++;
	rep(i, t.length()) cnt2[t[i] - 'a']++;
	sort(cnt1, cnt1 + 26);
	sort(cnt2, cnt2 + 26);
	rep(i, 26) if (cnt1[i] != cnt2[i]) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
#define MAX 1000000
bool sosu[MAX]={false};
int main(){
  for(int i=3;i<MAX;i+=2){
    if(sosu[i])continue;
    for(int j=i*3;j<MAX;j+=i*2)
      sosu[j]=true;
  }
  for(int i=4;i<MAX;i+=2)
    sosu[i]=true;
  int in;
  while(cin>>in){
    int co=0;
    loop(i,2,in+1)if(!sosu[i])co++;
    cout<<co<<endl;
  }


}

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

typedef pair<int, int> P;

int main()
{
	P p;
	vector<P> *List;
	int s, d, m, k, f, f1, f2, f3, **dp, outp, outc, cnt;
	while(scanf("%d %d %d",&s, &d, &m) != EOF)
	{
		outp = outc = cnt = 0;
		//メモリ確保と入力
		//メモリ確保
		List = new vector<P>[s];
		dp = new int *[d+1];
		for(f1 = 0; f1 <= d; f1++)
		{
			dp[f1] = new int [m+1];
		}
		//入力
		for(f1 = 0; f1 < s; f1++)
		{
			scanf("%d",&k);
			for(f2 = 0; f2 < k; f2++)
			{
				scanf("%d %d",&p.first,&p.second);
				List[f1].push_back(p);
			}
		}
		//動的計画法(DP)
		for(f1 = 0; f1 <= m; f1++)
			dp[0][f1] = 0;
		for(f1 = 1; f1 <= d; f1++)
		{
			scanf("%d",&f);
			if(f < s){
				cnt++;
				//内容をコピーする
				for(f3 = 0; f3 <= m; f3++)
					dp[f1][f3] = dp[f1-1][f3];
				//初期
				for(f2 = 0; f2 < (int)List[f].size(); f2++)
				{
					p = List[f][f2];
					for(f3 = m - p.second; f3 >= 0; f3--)
					{
						int tmp = f3 + p.second;
						dp[f1][tmp] = (dp[f1][tmp] < dp[f1][f3] + p.first) ? dp[f1][f3] + p.first : dp[f1][tmp];
					}
				}
			}
		}
		for(f1 = 0; f1 <= m; f1++)
		{
			if(outp < dp[cnt][f1])
			{
				outp = dp[cnt][f1];
				outc = f1;
			}
		}
		printf("%d %d\n",outp, outc);
	}
	return 0;
}

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

namespace AtCoderMake
{
    class ABC081A
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            Console.WriteLine(n.Count((x) => x == '1'));
        }
    }
}

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


ll INF = 1L << 60;
ll h[100010];
ll dps[100010];
int K;

// n番目のジャンプ台まで到達するための最小コストを返す
int dp(int n) {
  if (n == 0) {
     return 0;
  }
  if (dps[n] < INF) {
    return dps[n];
  }
  
  ll val = INF;
  for (int i = 1; i <= K; i++){
    if (n - i < 0){
      break;
    }
    val = min(val, dp(n-i) + abs(h[n] - h[n-i])); 
  }
  dps[n] = val;
  return dps[n];
}

int main() {
  int N;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    cin >> h[i];
  }
  for (int i = 0; i < 100010; i++){
    dps[i] = INF;
  }
  
  int min = dp(N-1);
  cout << min << endl;
}


Measured memory_bytes: 8064
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	string S;

	int i,j;
	int cnt = 0;
	cin >> S;

	for (i = 0; i < S.length() / 2;i++){
		if (S[i] != S[S.length()-1 - i]){
			cnt++;
		}
	}

	cout << cnt << endl;
	
	return 0;
}

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

const int MAX = 100000;

int main(){
    int h, n;
    int a;
    cin >> h >> n;

    int damage = 0;
    rep(i,n){
        cin >> a;
        damage += a;
    }

    if(damage >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    vector<int> v2(v);
    sort(ALL(v2));
    
    int l = v2[n/2-1], r = v2[n/2];
    REP(i,n) {
        if (v[i] < r) OUT(r)
        else OUT(l)
    }

    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <string>

using namespace std;
int main()
{
	string s;
	cin >> s;
	
	string c;

	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			c += s.at(i);
		}
	}

	cout << c << endl;
}

Measured memory_bytes: 512
#include<cstdio>
struct r{
	int to,last;
}e[200050];
int n,m,d[100050],cnt,num=2,head[100050],p1,p2,vis[200050];
void add(int u,int v){e[num].to=v;e[num].last=head[u];head[u]=num++;}
bool dfs(int u){
	if (u==p2)return 1;
	for (int i=head[u];i;i=e[i].last)if (!vis[i]){
		vis[i]=vis[i^1]=1;
		if (dfs(e[i].to))return 1;
	}
	return 0;
}
bool pd(){
	for (int i=1;i<=n;i++)if (d[i]==4)(!p1)?p1=i:p2=i;
	dfs(p1),dfs(p1);
	return dfs(p1)?0:1;
}
int main(){
	int u,v;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)scanf("%d%d",&u,&v),d[u]++,d[v]++,add(u,v),add(v,u);
	for (int i=1;i<=n;i++)if ((d[i]%2)){printf("No\n");return 0;}
	for (int i=1;i<=n;i++)if (d[i]>=6){printf("Yes\n");return 0;}else if (d[i]==4)cnt++;
	if (cnt>2)printf("Yes\n");
	else if (cnt==2&&pd())printf("Yes\n");
	else printf("No\n");
} 

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y>>z;
if(x%(y+z)==0)std::cout << x/(y+z)*y << '\n';
else if(x%(y+z)<=y)std::cout << x/(y+z)*y+x%(y+z) << '\n';
else std::cout << x/(y+z)*y+y << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S;
  
  for(int i=0; i<N; i++){
    cin >> S;
    
    if(S == "Y"){
      break;
    } 

  } 
  
  if(S =="Y"){
    cout << "Four" << endl;
  }
  
  else{
  cout << "Three" << endl;
  }
  
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

eat = []

# 食べる
p.sort(reverse=True)
if X > A:
    eat.extend(p)
else:
    eat.extend(p[:X])

q.sort(reverse=True)
if Y > B:
    eat.extend(q)
else:
    eat.extend(q[:Y])
loss = X+Y - len(eat)

# 足りない分を補充する
while loss > 0:
    r.sort(reverse=True)
    eat.append(r.pop(0))    
    loss -= 1

# rの方が大きいものがあれば入れ替える
eat.sort()
r.sort()
for i in range(len(eat)):
    if len(r) != 0 and eat[i] < r[-1]:
        eat[i] = r.pop(-1)
    else:
        break

print(sum(eat))


Measured memory_bytes: 23328
S = list(input())

first_clock = 0
last_clock = 0
F_count = 0
L_count = 0
count = -1

for i in S:
    count += 1
    if i == "A" and first_clock == 0:
        F_count = count
        first_clock = 1
    if i == "Z":
        L_count = count

else:
    print(L_count - F_count + 1)


Measured memory_bytes: 4840