akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  const int all_visited = (1 << N) - 1;
  auto dfs = [&](auto rec, int v, int visited) -> i64 {
    if (visited == all_visited) return 1LL;
    i64 res = 0;
    for (auto u : G[v]) {
      if (visited & (1 << u)) continue;
      res += rec(rec, u, visited | (1 << u));
    }
    return res;
  };

  i64 ans = dfs(dfs, 0, 1);
  cout << ans << '\n';
}

Measured memory_bytes: 3584
o,f,i=998244353,[1],1
while i<o>>8:f+=[f[-1]*i%o];i+=1
c=lambda n,k:f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split());w,u=3*m,n-1;a=c(w+u,u)-n*c(n+m-2,u)
while-~m<min(w,n):m+=2;a-=c(n,m)*c(2*u+w-m>>1,u)
print(a%o)

Measured memory_bytes: 129100
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll=long long;
#include <set>
#include <queue>
using namespace std;
ll gcd(ll x,ll y){
    if(y==0){
        return x;
    }else{
        return gcd(y,x%y);
    }
}
int main(){
    ll x,y,z,k;
    cin  >> x >> y >> z >> k;
    vector<ll> X(x);
    vector<ll> Y(y);
    vector<ll> Z(z);
    //cout<<x<<endl;
    for(int i=0;i<x;i++){
        cin >> X[i];
     //  cout<<X[i]<<endl;
    }
    for(int i=0;i<y;i++){
        cin >> Y[i];
    }
    for(int i=0;i<z;i++){
        cin >> Z[i];
    }
   // cout<<X[0]<<endl;
    sort(X.begin(),X.end(),greater<ll>());
    sort(Y.begin(),Y.end(),greater<ll>());
    sort(Z.begin(),Z.end(),greater<ll>());
  //int a=0;int b=0;int c=0;
   // cout<<X[0]+Y[0]+Z[0]<<endl;
   priority_queue<ll> q;
    for(int i=0;i<min(x,k);i++){
        for(int j=0;j<min(y,k);j++){
            q.push(X[i]+Y[j]);
          //  cout<<X[i]<<" "<<Y[j]<<endl;
        }
    }
 //   cout<<q.top()<<endl;
 ll p=q.size();
    vector<ll> sum;
    for(int i=0;i<min(p,k);i++){
        ll k=q.top();
        q.pop();
        for(int j=0;j<min(z,k);j++){
            sum.push_back(k+Z[j]);
        }
    }
    sort(sum.begin(),sum.end(),greater<ll>());
    for(int i=0;i<k;i++){
        cout<<sum[i]<<endl;
    }
}

Measured memory_bytes: 43260
N = int(input())
dp = [float('inf')]*100001
dp[0],dp[1] = 0,1
L = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
for i in range(2,100001):
  for j in range(len(L)):
    if i-L[j] >= 0:
      dp[i] = min(dp[i-L[j]]+1,dp[i])
print(dp[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define int long long
    



signed main(){
    int n,a1,a2,t;
    cin >> n >>a1;
    for(int i=1;i<n;i++){
        cin >>a2;
        if(a1<a2){
                t=a2;
                a2 =a1;
                a1 =t;

            }
        while(a2!=0){
            a1 = a1%a2;
            if(a1<a2){
                t=a2;
                a2 =a1;
                a1 =t;

            }
        }
    }
    cout << a1;

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


ll attack(ll h){
	if(h==1){
		return 1;
	}else{
		return (2*attack(h/2)+1);
	}
}

int main(){
	ll h;
	cin >> h;

	ll ans = attack(h);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 404;
typedef pair<int,int> i2;

const int di[] = {0,1};
const int dj[] = {1,0};
int n,m;
char c[N][N];
vector <int> a[N * N];
int kt[N * N];
int TS[N * N];
void nhap()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) cin >> c[i][j];
    }
}

void DFS(int u,int &SL,int &Value) {
    kt[u] = 1;
    Value += TS[u];
    SL++;
    for (int v : a[u]) {
        if (kt[v] == 0) DFS(v,SL,Value);
    }
}
void solve()
{
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int u = (i - 1) * m + j;
            TS[u] = (c[i][j] == '#' ? 1 : -1);
            for (int h = 0; h < 2; h++) {
                int x = i + di[h];
                int y = j + dj[h];
                if (x > 0 && x <= n && y > 0 && y <= m && c[i][j] != c[x][y]) {
                    int u = (i - 1) * m + j;
                    int v = (x - 1) * m + y;
                    a[u].push_back(v);
                    a[v].push_back(u);
                }
            }
        }
    }
    long long Res = 0;
    for (int i = 1; i <= n * m; i++) {
        int SL = 0;
        int Value = 0;
        if (kt[i] == 0) {
            DFS(i,SL,Value);
            int SL1 = (SL + Value) >> 1;
            int SL2 = SL - SL1;
            Res += 1ll * SL1 * SL2;
        }
    }
    cout << Res;
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    int odd = 0;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    int mx = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
        mx = max(mx, (int)g[i].size());
        if (g[i].size() == 4) {
            cnt++;
        }
        if (g[i].size() % 2 == 1) {
            puts("No");
            return 0;
        }
    }
    if (mx >= 6 || cnt >= 3) {
        puts("Yes");
        return 0;
    }
    if (mx == 2 || cnt < 2) {
        puts("No");
        return 0;
    }
    int x = -1, y;
    for (int i = 0; i < n; i++) {
        if (g[i].size() == 4) {
            y = i;
            if (x == -1) {
                swap(x, y);
            }
        }
    }
    int ok = 4;
    function<void(int, int)> dfs = [&](int v, int p) {
        for (int to : g[v]) {
            if (to == p) continue;
            if (to == y) {
                ok--;
                break;
            }
            if (to == x) {
                break;
            }
            dfs(to, v);
        }
    };
    dfs(x, -1);
    if (ok) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<cstdlib>

using namespace std;

int main() {
	int n;
	cin >> n;
	string* a = new string[n];
	string* b = new string[n];
	string* c = new string[n];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		b[i] = c[i] = a[i];
	}
	//Bubble sort
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = 0;i < n - 1;i++) {
			if (atoi(b[i].substr(1, 1).c_str()) > atoi(b[i + 1].substr(1, 1).c_str())) {
				flag = true;
				swap(b[i], b[i + 1]);
			}
		}
	}

	for (int i = 0;i < n - 1;i++) {
		cout << b[i] << " ";
	}
	cout << b[n - 1] << endl;
	flag = true;
	for (int i = 0;i < n-1&&flag;i++) {
		if (b[i][1] == b[i + 1][1]) {
			for (int j = 0;j < n;j++) {
				if (a[j] == b[i])break;
				if (a[j] == b[i + 1]) {
					flag = false;
					break;
				}
			}
		}
	}
	if (flag)cout << "Stable\n";
	else cout << "Not stable\n";

	//選択ソート
	int minj;
	for (int i = 0;i < n - 1;i++) {
		minj = i;
		for (int j = i + 1;j < n;j++) {
			if (atoi(c[j].substr(1,1).c_str()) < atoi(c[minj].substr(1,1).c_str()))minj = j;
		}
		if (minj != i) {
			swap(c[i], c[minj]);
		}
	}
	for (int i = 0;i < n - 1;i++) {
		cout << c[i] << " ";
	}
	cout << c[n - 1] << endl;
	flag = true;
	for (int i = 0;i < n - 1 && flag;i++) {
		if (c[i][1] == c[i + 1][1]) {
			for (int j = 0;j < n;j++) {
				if (a[j] == c[i])break;
				if (a[j] == c[i + 1]) {
					flag = false;
					break;
				}
			}
		}
	}
	if (flag)cout << "Stable\n";
	else cout << "Not stable\n";
}


Measured memory_bytes: 3212
# A - Digits Sum

N = input()
N_int = int(N)
mylist = ['10','100','1000','10000','100000']
ans = 0

if N in mylist:
    ans = 10
else:
    for i in range(len(N)):
        ans += (N_int % 10)
        N_int = N_int // 10

print(ans)

Measured memory_bytes: 3060
(defun split (string &key (delimiterp #'delimiterp))
  (loop :for beg = (position-if-not delimiterp string)
    :then (position-if-not delimiterp string :start (1+ end))
    :for end = (and beg (position-if delimiterp string :start beg))
    :when beg :collect (subseq string beg end)
    :while end))

(defun delimiterp (c) (position c " ,.;/"))

(defun solve (dislike_digits_table first_like_digit N_str)
  (loop :for c :across N_str :and idx :from 0 :do
        (loop :while (nth (digit-char-p c) dislike_digits_table)
              :do
                  (cond ((eq c #\9)
                          (if (= idx 0)
                              (return-from solve (solve dislike_digits_table first_like_digit (concatenate 'string "1" (make-string (length N_str) :initial-element #\0))))
                            (return-from solve (solve dislike_digits_table first_like_digit (concatenate 'string (write-to-string (+ (parse-integer (subseq N_str 0 (+ idx 1))) 1)) (make-string (length (subseq N_str (+ idx 1))) :initial-element #\0))
                                   ))))
                        (t
                          (setq c (digit-char (+ (digit-char-p c) 1)))))
                  (setf (char N_str idx) c)
                  (setf (subseq N_str (+ idx 1)) (make-string (length (subseq N_str (+ idx 1))) :initial-element #\0))
              )
        )
  N_str
  )


(defun main()
  (let* ((N (read))
         (K (read))
         (D (read-line))
         (digits (split D))
         (dislike_digits_table (make-list 10))
         (first_like_digit nil)
         )
    (loop :for digit :in digits :collect
          (setf (nth (parse-integer digit) dislike_digits_table) t))
    (setq first_like_digit (position t dislike_digits_table))

    (princ (solve dislike_digits_table first_like_digit (write-to-string N))) (princ '#\newline)))

(main)

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

int main() {
int n, ans;
cin >> n;
    ans = pow(n, 3);
cout << ans << endl;
}


Measured memory_bytes: 3248
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

int main(){
  int n, m;
  std::cin >> n >> m;

  vector<int> k(m);
  vector< vector<int> > s(m, vector<int>(n, 0));
  vector<int> p(m);

  for (int i = 0; i < m; i++) {
    std::cin >> k[i];
    int si;
    for (int j = 0; j < k[i]; j++) {
      std::cin >> si;
      s[i][si-1] = 1;
    }
  }

  for (int i = 0; i < m; i++) {
    std::cin >> p[i];
  }

  int ans = 0;

  for (int i = 0; i < (1<<(n)); i++) {
    int t;
    int x;
    bool flag = true;
    for (int j = 0; j < m; j++) {
      t = i;
      x = 0;
      for (int k = 0; k < n; k++) {
        x ^= (s[j][k] & (t%2));
        t = t>>1;
      }
      if(x != p[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }

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

  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  string s,t;
  cin >> s >> t;
  sort(ALL(s));
  sort(ALL(t));
  reverse(ALL(t));

  cout << (s < t ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans;
int main(){
	int n,st,en;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&st,&en);
		ans+=en-st+1;
	}
	printf("%d\n",ans);
	return 0;
	}


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

int main(void){
    int n, tt, max=100000;
    int c[110], t[110];
    cin >> n >> tt;
    for(int i=0;i<n;++i){
        cin >> c[i] >> t[i];
        if(t[i] <= tt){
            if(max > c[i]) max = c[i];
        }
    }
    if(max == 100000) cout << "TLE" << endl;
    else cout << max << endl;
}

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

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

  if (s == "Sunny") cout << "Cloudy" << endl;
  else if (s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

// ref: https://github.com/beet-aizu/library/blob/master/flow/dinic.cpp
template <typename T, bool directed>
struct Dinic {
    struct edge {
        int to;
        T cap;   // capacity of the edge
        int rev; // index for to->from edge
        edge() {}
        edge(int to_, T cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {}
    };
    T inf = numeric_limits<T>::max();
    vector<vector<edge>> G;
    vector<int> level, iter;
    Dinic(int n) : G(n), level(n), iter(n) {}

    void addEdge(int from, int to, T cap) {
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, directed ? 0 : cap, G[from].size() - 1);
    }
    void bfs(int s) {
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.emplace(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (edge &e : G[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.emplace(e.to);
                }
            }
        }
    }
    T dfs(int v, int t, T f) {
        if (v == t)
            return f;
        for (int i = iter[v]; i < int(G[v].size()); ++i) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                T d = dfs(e.to, t, min(f, e.cap));
                if (d == 0)
                    continue;
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return 0;
    }
    T maxFlow(int s, int t, T lim) {
        T fl = 0;
        while (true) {
            bfs(s);
            if (level[t] < 0 || lim == 0)
                break;
            fill(iter.begin(), iter.end(), 0);
            while (true) {
                T f = dfs(s, t, lim);
                if (f == 0)
                    break;
                fl += f;
                lim -= f;
            }
        }
        return fl;
    }
    // returns maximum flow from s to t
    T maxFlow(int s, int t) { return maxFlow(s, t, inf); }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    lint ret = 0;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] > 0)
            ret += a[i];
    }
    Dinic<lint, true> dinic(n + 2);
    int s = 0, t = n + 1;
    for (int i = 0; i < n; ++i) {
        if (a[i] <= 0) {
            dinic.addEdge(s, i + 1, -a[i]);
        } else {
            dinic.addEdge(i + 1, t, a[i]);
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 2 * i; j <= n; j += i) {
            dinic.addEdge(i, j, inf);
        }
    }
    ret -= dinic.maxFlow(s, t);
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split(' '))
S = input()
T = input()

def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    else:
        return gcd(b, a - b)

lcm = N * M // gcd(N, M)
s_c_dict = dict([[j, S[i]] for i, j in enumerate(range(0, lcm, lcm//N))])
for i, j in enumerate(range(0, lcm, lcm//M)):
    if j in s_c_dict:
        if s_c_dict[j] != T[i]:
            print(-1)
            exit()
print(lcm)


Measured memory_bytes: 65060
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline ll read(){
	ll n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int mo=1e9+7;
int Q,i,j,ans;
ll X,Y,inf=1e18+1,f[105];
struct ar{ll x,y;};
vector<ar>p[105];
int main(){
	f[0]=f[1]=1;
	fo(i,2,89) f[i]=f[i-1]+f[i-2];
	p[1].push_back((ar){1,2});
	p[1].push_back((ar){1,3});
	fo(i,1,86){
		ll mx=min(inf,f[i+3]+f[i]);
		for(j=0;j<p[i].size();j++){
			ar now=p[i][j],ne;
			ne=(ar){now.y,now.y+now.x};
			for(;ne.y<mx;ne.y+=now.y)p[i+1].push_back(ne);
		}
	}
	Q=read();
	for(;Q--;){
		X=read(),Y=read();
		if (X>Y) swap(X,Y);
		ans=1;
		for(;f[ans+1]<=X&&f[ans+2]<=Y;ans++);
		printf("%d ",ans);
		if (ans==1){
			printf("%d\n",X*Y%mo);
			continue;
		}
		ans--;
		ll num=0;
		for(i=0;i<p[ans].size();i++){
			ar now=p[ans][i];
			if (now.y<=X) (num+=(Y-now.x)/now.y)%=mo;
			if (now.y<=Y) (num+=(X-now.x)/now.y)%=mo;
		}
		printf("%d\n",num);
	}
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b; cin >> a >> b;
	
	if((a + b) % 2){
		cout << "IMPOSSIBLE" << endl;
	}
	else cout << (a + b) / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

string s, t;
int n, m, i;
bool ok;

void check(int d, int k){
    if (d == k - 1){
        int j = 0;
        while (i < n){
            if (s[i] == t[j]){
                j++;
            }
            i++;
            if (j == m) break;
        }
        if (j < m) ok = false;
    }else{
        int j = 0;
        check(d + 1, k);
        while (i < n){
            if (s[i] == t[j]){
                i++;
                j++;
                check(d + 1, k);
                if (j == m) break;
            }else{
                i++;
            }
        }
        if (j < m) ok = false;
    }
}

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

    n = s.length(), m = t.length();

    int ans = 0;
    FOR(k,1,20){
        // cout << "check " << k << endl;
        ok = true;
        i = 0;
        check(0, k);

        if (ok) ans = k;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3332
a,b,c =map(int,input().split())

if a <= b and b <= c:
	print(a,b,c)
elif a <= c and c <= b:
	print(a,c,b)
elif b <= a and a <= c:
	print(b,a,c)
elif b <= c and c <= a:
	print(b,c,a)
elif c <= a and a <= b:
	print(c,a,b)
elif c <= b and b <= a:
	print(c,b,a)


Measured memory_bytes: 5596
#include <stdio.h>
#include <string.h>
int main(){
    char s[1001], com[10], tex[1001], temp;
    int n, a, b, i, l;
    scanf("%s", &s);
    scanf("%d", &n);
    while(n--){
        scanf("%s %d %d", &com, &a, &b);
        if(strcmp(com, "replace")==0){
            scanf("%s", &tex);
            l = strlen(tex);
            for(i=0;i<l;i++){
                s[a+i] = tex[i];
            }
        }else if(strcmp(com, "reverse") == 0){
            for(a=a, b=b; a<=b ; a++, b--){
                temp = s[a];
                s[a] = s[b];
                s[b] = temp;
            }
        }else{
            for(a=a;a<=b;a++){
                printf("%c",s[a]);
            }printf("\n");
        }
    }

return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef tuple<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef unordered_set<ll> si;
typedef unordered_map<ll, ll> mii;

bool ok;

void dfs(const vvii &g, si &s, mii &c, int i) {
	if (!ok) return;
	for (auto z : g[i]) {
		ll j, d;
		tie(j, d) = z;
		if (c.find(j) != c.end()) {
			if (c[j] - c[i] != d) {
				ok = false;
				return;
			}
		} else c[j] = c[i] + d;
		auto it = s.find(j);
		if (it != s.end()) {
			s.erase(it);
			dfs(g, s, c, j);
		}
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	vvii g(n);
	for (int i = 0; i < m; i++) {
		ll l, r, d;
		cin >> l >> r >> d;
		l--;
		r--;
		g[l].push_back(make_tuple(r, d));
		g[r].push_back(make_tuple(l, -d));
	}
	si s;
	for (int i = 0; i < n; i++) s.insert(i);
	ok = true;
	while (!s.empty()) {
		auto it = s.begin();
		s.erase(it);
		mii c;
		c[*it] = 0;
		dfs(g, s, c, *it);
	}
	cout << (ok ? "Yes\n" : "No\n");
}


Measured memory_bytes: 24252
//#pragma GCC optimize (2)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(),v.end()
ll quick_pow(ll base, ll n) {
    ll ans = 1;
    while (n ) {
        if (n & 1 )
            ans *= base;
        base *= base;
        n >>= 1;
    }
    return ans;
}
void solve();
int main() {
    int T=1;
//    cin>>T;
    while (T--){
        solve();
    }
    return 0;
}
int a[10005];
void solve() {
    int n;
    cin >> n;
    int t;
    for (int i = 1; i <= 101 ; ++i) {
        for (int j = 1; j <= 101; ++j) {
            for (int k = 1; k <= 101; ++k) {
                t = i * i + j * j + k * k + i * j + j * k + k * i;
                if (t <= 10000)
                    a[t]++;
            }
        }
    }
    for (int l = 1; l <= n; ++l) {
        cout << a[l] << endl;
    }
}


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

int h,w;
char b[100][101];
bool visit[100][100];

int main(){
	while(cin>>h>>w,h|w){
		cin.ignore();
		for(int i=0;i<h;i++)cin>>b[i];
		int y=0,x=0;
		memset(visit,false,sizeof(visit));
		while(!visit[y][x]&&b[y][x]!='.'){
			visit[y][x]=true;
			if(b[y][x]=='>')x++;
			else if(b[y][x]=='<')x--;
			else if(b[y][x]=='^')y--;
			else if(b[y][x]=='v')y++;
		}
		if(visit[y][x])cout<<"LOOP"<<endl;
		else cout<<x<<' '<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1192
def main(arg):
    arg = int(arg)
    h,m,s=0,0,0
    while arg >= 3600:
        arg -= 3600
        h += 1
    while arg >= 60:
        arg -= 60
        m += 1
    s = arg
    result = "{}:{}:{}".format(h,m,s)
    return result


if __name__ == '__main__':
    print(main(input()))

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

using namespace std;

vector<int> next_int_vector(int n) {
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v.at(i);
    }
    return v;
}

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3656
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

//文字列としての数字を
//整数数型に変換する関数
long long getint(string str) {
	long long ret = 0;

	for (int i = 0; i < str.size(); i++) {
		ret = ret * 10 +(str[i] - '0');
	}

	return ret;
}

int main() {

	string s; cin >> s;

	//一文字なら＋を入れる余地がないので、表示して終了
	if (s.size() == 1) {
		cout << s << endl;
		return 0;
	}
	

	//s[0] s[1] s[2]…という添字の向きだと扱いにくいのでひっくり返す
	//…s[2] s[1] s[0]になる
	reverse(s.begin(), s.end());

	long long ans = 0;

	//＋が入る隙間の数
	int l = s.size() - 1;

	//＋の有無のパターンを全列挙
	//ビットが立ってる位置には＋を入れる

	//…s[2] l[1] s[1] l[0] s[0]
	//という対応になっている
	for (int bit = 0; bit < (1 << l); bit++) {
		
		//各＋の間にある数字を表す文字列
		string tmp ="";

		tmp += s[0];
		
		//＋が入る隙間の位置i
		for (int i = 0; i < l; i++) {

			if ((bit >> i) & 1) {
				ans += getint(tmp);
				tmp = s[i+1];
			}
			else {
				tmp= s[i+1]+tmp;
			}

			//一番左の数字を最後に回収
			if (i == l - 1) {
				ans += getint(tmp);
			}
		}
	}

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

Measured memory_bytes: 384
// Problem : D - Road to Millionaire
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 82 

//Solution

int n,a[N];

void solve(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    int cash = 1000;
    int stocks = 0;
    for(int i=0;i<n-1;i++){
        if(a[i] < a[i+1]){
            stocks = cash/a[i];
            cash -= stocks*a[i];
            cash += stocks*a[i+1];
        }
    }
    cout<<cash;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

int main(){
    string s,t; cin >> s >> t;
    vector<vector<int>> memo(26);
    int cur = 0; //今何週目を見ているか
    int dex = 0; //次に何文字目をみるか
    ll ans = 0;
    for(int i = 0; i < s.size(); i++){
        memo[s[i]-'a'].push_back(i);
    }
    int judge = 1;
    for(int i = 0; i < t.size(); i++){
        if(memo[t[i]-'a'].size() == 0){
            judge = 0;
            cout << -1 << endl;
            break;
        }
        int curjudge = 1;
        /*for(int j = 0; j < memo[t[i]-'a'].size(); j++){
            if(dex <= memo[t[i]-'a'][j]){
                curjudge = 0;
                dex = memo[t[i]-'a'][j] + 1;
                break;
            }
        }*/
        int index = int(lower_bound(memo[t[i]-'a'].begin(),memo[t[i]-'a'].end(),dex) - memo[t[i]-'a'].begin() );
        if(index < memo[t[i]-'a'].size() && dex <= memo[t[i]-'a'][index]){
            dex = memo[t[i]-'a'][index] + 1;
            curjudge = 0;
        }
        if(curjudge){
            cur++;
            dex = memo[t[i]-'a'][0]+1;
        }
    }
    if(judge) cout << cur*s.size() + dex << endl;
}

Measured memory_bytes: 1344
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>

using ii = std::pair<int, int>;

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

	std::vector<int> arr(n + 1);

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &arr[i]);
	}

	int count = 0;

	for (int i = 1; i < n; i++)
	{
		if (arr[i] == i && arr[i + 1] == i + 1)
		{
			std::swap(arr[i], arr[i + 1]);
			count++;
		}
	}

	for (int i = 1; i <= n; i++)
	{
		if (arr[i] != i)
			continue;

		if(i!=n)
			std::swap(arr[i], arr[i + 1]);

		count++;
	}

	printf("%d", count);

	return 0;
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int result = 0;
		int total = 1;
		while (B > total) {
			total += A - 1;
			result++;
		}
		System.out.println(result);
		
	}
	
	private static int kaijo(int x) {
		int result = 1;
		for(int i = 1; i <= x; ++i) result *= 2;
		return result;
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    string s; cin >> s;
    int count = 0;
    REP(i, s.size()){
        if(s[i] == 'x') count++;
    }
    cout << (count < 8 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << '\n';
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    
    int max_abs = 0, max_abs_idx = 0;
    bool plus = true;
    for (int i = 0; i < N; i++) {
        if (abs(a[i]) > max_abs) {
            max_abs = abs(a[i]);
            max_abs_idx = i;
            plus = (a[i] >= 0);
        }
    }

    cout << 2 * (N-1) << '\n';
    for (int i = 0; i < N; i++) {
        if (i == max_abs_idx) continue;
        print(max_abs_idx+1, i+1);
    }
    if (plus) {
        for (int i = 1; i < N; i++) {
            print(i, i+1);
        }
    }
    else {
        for (int i = N; i > 1; i--) {
            print(i, i-1);
        }
    }
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()
 
const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
ll power(ll x, ll y, ll p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
} 
void solve()
{
	ll n,x,p;
	cin>>n>>x>>p;
	ll it=0;
	vector<int>a(1e5+1,0),pos(1e5+1,0);
	map<ll,ll>mp;
	a[0]=x;
	mp[x]++;
	pos[x]=0;
	it++;
	x=power(x,2,p);
	while((mp[x]==0)&&(it<n))
	{
	a[it]=x;
	mp[x]++;
	pos[x]=it;
	it++;
	x=power(x,2,p);
	}
	//for(ll i=0;i<it;i++)
	//cout<<a[i]<<endl;
	if(it==n)
	{
		ll ans=0;
		for(ll i=0;i<n;i++)
		{
			ans+=a[i];
		}
		cout<<ans<<endl;
	}
	else
	{
		ll y=pos[x];
		ll z=it-y;
		ll ans=0;
		for(ll i=0;i<it;i++)
		{
			ans+=a[i];
		}
		//cout<<ans<<endl;
		n=n-it;
		ll val=0;
		for(ll i=y;i<it;i++)
		{
			val+=a[i];
		}
		ans+=val*(n/z);
		for(ll i=y;i<y+n%z;i++)
		ans+=a[i];
		cout<<ans<<endl;
	}
}
 
int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    int ans=1;
    int com=1;
    for(int i=0;i<n;i++){
        cin >> a[i];
        ans*=3;
        if(a[i]%2==0){
            com*=2;
        }
    }
    cout << ans-com << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
const int maxn = 100005;
typedef pair<int, int> pii;
int N, f[maxn];
set<int> st[maxn];
queue<pii> q;
int find(int x) {
	return f[x] == x ? x : f[x] = find(f[x]);
}
bool merge(int x, int y) {
	// printf("%d %d\n", x, y);
	x = find(x), y = find(y);
	if(x == y) return false;
	if(st[x].size() < st[y].size()) swap(x, y);
	f[y] = x;
	for(set<int>::iterator it = st[y].begin(); 
		it != st[y].end(); ++it) {
		int t = find(*it);
		if(x == t) continue;
		if(st[x].count(t)) q.push(pii(x, t));
		else st[x].insert(t), st[t].insert(x);
	}
	st[y].clear(), st[x].erase(y);
	return true;
}
int main() {
	scanf("%d", &N);
	for(int i = 1, u, v; i < N + N - 1; ++i) {
		scanf("%d%d", &u, &v);
		if(st[u].count(v)) q.push(pii(u, v));
		st[u].insert(v), st[v].insert(u);
	}
	for(int i = 1; i <= N; ++i) f[i] = i;
	int cnt = 0;
	while(!q.empty()) {
		pii x = q.front(); q.pop();
		cnt += merge(x.first, x.second);
	}
	puts(cnt == N - 1 ? "YES" : "NO");
	getchar(), getchar();
	return 0;
}

Measured memory_bytes: 24064
#include <iostream>
#include<cstdio>
#include <cstring>
#include <map>
#define maxn 3000000+5
using namespace std;
const long long mod = 200907;
int main()
{
    string t="keyence";
    string s;cin>>s;
    if(s.substr(0,7)==t){
        printf("YES");
    }else if(s.substr(s.size()-7,7)==t){
        printf("YES");
    }else {
        int flag=0;
        for(int i=1;i<=t.size();i++){
            int len=t.size()-i;
            int s1=i,s2=s.size()-len;
            if(s.substr(0,i)==t.substr(0,i)&&t.substr(s1,len)==s.substr(s2,len))flag=1;
        }
        if(flag)printf("YES");
        else printf("NO");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    
    for(int i=0;i<n;i++)
    cin>>a[i];
    int i,j=0,m,k;
    m=a[0];
    for(i=0;i<n;i++)
    {
        m=min(m,a[i]);
        if(m==a[i])
        j++;
    }
    cout<<j;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    map<string, int> memo;
    int n;
    cin >> n;
    rep(i, 0, n) {
        string s;
        cin >> s;
        memo[s]++;
    }
    cout << "AC x " << memo["AC"] << '\n';
    cout << "WA x " << memo["WA"] << '\n';
    cout << "TLE x " << memo["TLE"] << '\n';
    cout << "RE x " << memo["RE"] << '\n';


    return 0;
}



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

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

using namespace std;

using ll = long long;

template <class Pred>
ll partition_point_ll(ll first, ll last, Pred p) {
    ll count = last - first;
    while (count > 0) {
        ll step = count / 2;
        ll mid = first + step;
        if (p(mid)) {
            first = mid + 1;
            count -= step + 1;
        } else {
            count = step;
        }
    }
    return first;
}

int main() {
    const int H_MAX = 1000000000;
    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> h(N);
    REP(i, N) cin >> h[i];

    int C = A - B;
    auto f = [&](ll t) {
        ll count = 0;
        REP(i, N) {
            ll x = h[i] - t * B;
            if (x > 0) {
                count += (x + C - 1) / C;
            }
        }
        return count > t;
    };
    cout << partition_point_ll(0, (H_MAX + B - 1) / B, f) << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		long count = 0;
		if (a[0] > x) {
			count += a[0] - x;
			a[0] -= a[0] - x;
		}
		for (int i = 1; i < n; i++) {
			if (a[i] + a[i - 1] > x) {
				count += a[i] + a[i - 1] - x;
				a[i] -= a[i] + a[i - 1] - x;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 59936
import bisect
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    C.sort()

    ans = 0
    for target in B:
        A_lower = bisect.bisect_left(A, target)
        C_upper = bisect.bisect_right(C, target)
        ans += A_lower * (N - C_upper)
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
int n = 0, m = 0;
int fir[100500], nxt[200500], to[200500], rez[100500][2];
bool vis[100500];
void dfs1(int x, int fa)
{
	for(int i = fir[x]; i; i = nxt[i])
	{
		int t = to[i];
		if(t == fa) continue;
		dfs1(t, x);
		if(not vis[t]) continue;
		if(not vis[x])
		{
			rez[x][0] = rez[t][0] - 1;
			rez[x][1] = rez[t][1] + 1;
			vis[x] = true;
		}
		else
		{
			if(rez[x][0] > rez[t][1] + 1 || rez[x][1] < rez[t][0] - 1 || not ((rez[x][0] ^ rez[t][0]) & 1))
				cout << "No" << endl, exit(0);
			else rez[x][0] = max(rez[x][0], rez[t][0] - 1), rez[x][1] = min(rez[x][1], rez[t][1] + 1);
		}
	}
}
int ans[100500];
void dfs2(int x, int fa)
{
	if(not fa) ans[x] = rez[x][1];
	else if(not vis[x] || ans[fa] + 1 <= rez[x][1]) ans[x] = ans[fa] + 1;
	else ans[x] = ans[fa] - 1;
	for(int i = fir[x]; i; i = nxt[i])
	{
		int t = to[i];
		if(t == fa) continue;
		dfs2(t, x);
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1, j = 0; i < n; i++)
	{
		int a = 0, b = 0;
		cin >> a >> b;
		j++, nxt[j] = fir[a], fir[a] = j, to[j] = b;
		j++, nxt[j] = fir[b], fir[b] = j, to[j] = a;
	}
	cin >> m;
	for(int i = 1; i <= m; i++)
	{
		int x = 0, y = 0;
		cin >> x >> y;
		rez[x][0] = y, rez[x][1] = y, vis[x] = true;
	}
	dfs1(1, 0);
	dfs2(1, 0);
	cout << "Yes" << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 8832
input_str = list(map(int, input().split()))
# パターンを上げる
# 5 * 5 * 7 で１通りとする（素因数分解しても１通り）
# sortして１通りとする
# print("YES" if sorted([int(i) for i in input().split()])==[5,5,7] else "NO")
if input_str == [7, 5, 5] or input_str == [5, 7, 5] or input_str == [5, 5, 7]:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        A: i64,
        B: i64,
        C: i64,
    }

    if A <= C && C <= B {
        println!("Yes");
    } else if B <= C && C <= A {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)

int main(){

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


vi v;rep(i,1,3){int a;cin>>a;v.pb(a);}
sort(v.begin(),v.end());
int a=v[0],b=v[1],c=v[2];
if((a==b && b!=c) || (a!=b && b==c))cout<<"Yes";
else cout <<"No";
	return 0;
}


Measured memory_bytes: 256