akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#define ll long long;

using namespace std;

int n;
double ss;
int s[1000];
double m;
double a;

double mean(int s[]) {
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += s[i];
	}
	return (double)sum / n;
}

int main() {
	

	while (1) {
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		m = mean(s);
		ss = 0;
		for (int i = 0; i < n; i++) {
			ss += (s[i] - m)*(s[i] - m);
		}
		a = sqrt(ss / n);
		printf("%.8f\n", a);
	}
}

Measured memory_bytes: 3204
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

Measured memory_bytes: 56452
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))

a.sort()

#print(a)

ret = False
for i in range(n-1):
        #print(i)
        #print(a[i] == a[i+1])
        ret += (a[i] == a[i+1])

print('YES' if ret == 0 else 'NO')

Measured memory_bytes: 25172
#include <iostream>
using namespace std;
int main(void){
    int w, h ,x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && x+r <= w && y-r >= 0 && y+r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
        
    return 0;
}



Measured memory_bytes: 3092
// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

struct Graph {
    Graph(const int n)
    {
        edge.resize(n);
    }
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
    }
    vector<vector<int>> edge;
};

int dp_dfs(const Graph& g, const int s, const vector<int>& X)
{
    if (g.edge[s].empty()) {
        return 0;
    }
    unordered_map<int, int> prev;
    unordered_map<int, int> dp;
    prev[0] = 0;
    for (const int to : g.edge[s]) {
        const int Y = dp_dfs(g, to, X);
        cerr << to << ": " << Y << endl;
        for (const auto& e : prev) {
            if (e.first + X[to] <= X[s]) {
                const int v = e.first + X[to];
                if (dp.find(v) != dp.end()) {
                    dp[v] = min(dp[v], e.second + Y);
                } else {
                    dp[v] = e.second + Y;
                }
            }
            if (e.first + Y <= X[s]) {
                const int v = e.first + Y;
                if (dp.find(v) != dp.end()) {
                    dp[v] = min(dp[v], e.second + X[to]);
                } else {
                    dp[v] = e.second + X[to];
                }
            }
        }
        prev = dp;
        dp.clear();
    }
    int mini = INF<int>;
    for (const auto& e : prev) {
        mini = min(mini, e.second);
    }
    return mini;
}

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

    int N;
    cin >> N;
    Graph g(N);
    for (int i = 1; i < N; i++) {
        int from;
        cin >> from;
        from--;
        g.addEdge(from, i);
    }
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    if (N == 1) {
        cout << "POSSIBLE" << endl;
        return 0;
    }

    const int Y = dp_dfs(g, 0, X);
    cerr << 0 << ": " << Y << endl;

    if (Y == INF<int>) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << "POSSIBLE" << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

int main() {
  int r;
  cin >> r;
  printf("%.15f\n", r * 2 * M_PI);
  return 0;
}

Measured memory_bytes: 3724
N, A, B = map(int, input().split())
max = B*(N-1)+A
min = A*(N-1)+B

if(A > B):
    print(0)
elif(A == B):
    print(1)
else:
    if N > 1:
        print(max - min + 1)
    else:
        print(0)

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

using namespace std;

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	if(abs(A - B) % 2 == 0){
		cout << "Alice" << endl;
	} else{
		cout << "Borys" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,num = 0,k,flg = 0;
	
	scanf("%d%d%d", &k, &a, &b);

	while(1){
		num += k;

		if (num >= a && num <= b) {
			flg = 1;
			break;
		}

		if (num > 1000) {
			flg = 0;
			break;
		}
	}

	if (flg == 1) {
		printf("OK\n");
	}
	else {
		printf("NG\n");
	}

	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool ok = true;
    if(s[0] != 'm') ok = false;
    if(s.back() != 'w') ok = false;
    while(1)
    {
        string t = "";
        for(int i = 0; i < s.size(); i++)
        {
            if(i + 3 != s.size() && i != 0 && s.substr(i, 3) == "mew")
            {
                i += 2;
            }
            else
            {
                t += s[i];
            }
        }
        if(t == "mew") break;
        if(t == s)
        {
            ok = false; //変化なし
            break;
        }
        s = t;
    }
    cout << (ok ? "Cat" : "Rabbit") << endl;
    return 0;
}




Measured memory_bytes: 3224
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
    string s;
    ll cnt[2020];
int main(){

    cin>>s;
    int n=s.size();
    ll ans=0;
    cnt[0]=1;
    int tot=0;
    int p=1;
    for(int i=n-1;i>=0;i--){
        tot=(tot+(s[i]-'0')*p)%2019;
        ans+=cnt[tot];
        p=(p*10)%2019;
        cnt[tot]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3736
#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 itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MAX int(1e5+5)

int main(){
    int n,k;
    cin >> n >> k;
    llong A[MAX];
    REP(i,n) scanf("%lld",&A[i]);
    sort(A,A+n);
    llong ans = llong(1e15);
    int ind = 0;
    while(1){
        ans = min(ans , A[ind + k-1] - A[ind]);
        ind += 1;
        if(ind + k-1 >= n) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

public class Beginner
{
    public static void Main(string[] args)
    {
        var vals = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();
        var minus = 100 * (10 - vals[0]) < 0 ? 0 : 100 * (10 - vals[0]);
        Console.WriteLine(vals[1] + minus);
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <math.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return (a.first*a.first + a.second*a.second) > (b.first*b.first + b.second*b.second);
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

ll d2(pair<ll, ll> p) {
    return p.first*p.first+p.second*p.second;
}

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int ff = 0;
    int bb = 0;
    int hp = 0;
    REP(i, S.length()-1) {
        if (S[i] == S[i+1]) hp++;
        if (S[i] == 'L' && S[i+1] == 'R') bb++;
        if (S[i+1] == 'L' && S[i] == 'R') ff++;
    }
    
    int d = min(min(bb, ff), K);
    hp += 2*d;
    bb -= d;
    ff -= d;
    K -= d;
    
    if (S[0] == 'L') ff++;
    else bb++;
    
    if (S[N-1] == 'R') ff++;
    else bb++;
    
    if (S[0] == S[N-1]) {
        ff--;
        bb--;
    }
    
    cout << hp + min(min(bb, ff), K) << endl;
}


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

int main(){
  
  string s;
  cin >> s;
  int n = s.size()-1;
  int ans = s[0]-'0';
  vector<char>vec(n);
  for(int bit=0; bit<(1<<n);bit++){
    rep(i,n){
      int num=s[i+1]-'0';
      if(bit & (1<<i)){
        ans+=num;
        vec[i]='+';
      }
      else{
        ans -=num;
        vec[i]='-';
      }
    }
    if(ans == 7){
      cout<<s[0];
      rep(i,n) cout<<vec[i]<<s[i+1];
      cout << "=7"<<endl;
      return 0;
    }
    else ans = s[0]-'0';
  }
}


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

signed main(){
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        if(i*108/100==n){cout<<i<<endl;return 0;}
    }
    cout<<":("<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <fstream>
#pragma GCC optimize("O2")
using namespace std;

#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
long long const inf = 1e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 3e5 + 10 ;


ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}







int main(){
	string A ;
	cin>>A ; 
	if (A=="ABC")
		cout<<"ARC" ; 
	else
		cout<<"ABC" ; 
}	

Measured memory_bytes: 3592
#include<cstdio>
using namespace std;
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a==b) printf("%d\n",c);
  else if(a==c) printf("%d\n",b);
  else printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;
    if(u==s){
        cout << a-1 << " " << b << endl;
    }
    else{
        cout << a << " " << b-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve(t1, t2, a1, a2, b1, b2):
    sa = a1 * t1 + a2 * t2
    sb = b1 * t1 + b2 * t2
    if sa == sb:
        return "infinity"
    if a1 > b1:
        if sa >= sb:
            return 0
        else:
            d0 = a1 * t1 - b1 * t1
            d1 = sb - sa
            res = (d0 // d1 + 1) * 2 - 1
            if d0 % d1 == 0:
                res -= 1
    else:
        if sa <= sb:
            return 0
        else:
            d0 = b1 * t1 - a1 * t1
            d1 = sa - sb
            res = (d0 // d1 + 1) * 2 - 1
            if d0 % d1 == 0:
                res -= 1
    return res


def main():
    t1, t2 = map(int, input().split())
    a1, a2 = map(int, input().split())
    b1, b2 = map(int, input().split())
    res = solve(t1, t2, a1, a2, b1, b2)
    print(res)


def test():
    assert solve(1, 2, 10, 10, 12, 4) == 1
    assert solve(100, 1, 101, 101, 102, 1) == "infinity"
    assert solve(12000, 15700, 3390000000, 3810000000, 5550000000, 2130000000) == 113


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int S;
	cin >> S;
	int h,m,s;
	h = S/3600;
	int l;
	l = S%3600;
	m = l/60;
	s = l%60;
	cout <<h<<":"<<m<<":"<<s<<endl;
}


Measured memory_bytes: 3120
#include<iostream>
using namespace std;
const int N = 2e5+5;
int a[N];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n-k;i++)
    {
        if(a[i+k]>a[i])
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
    return 0;
}


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

const ll INF=1e9;

int main(){
    ll h,n;
    cin>>h>>n;
    vector<ll> a(n),b(n),dp(h+1,INF);
    dp[0]=0;
    rep(i,n) cin>>a[i]>>b[i];
    for(ll i=1;i<=h;i++){
        rep(j,n){
            if(a[j]>i) dp[i]=min(dp[i],b[j]);
            else dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
        }
    }
    cout<<dp[h]<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

// https://img.atcoder.jp/abc178/editorial-E-phcdiydzyqa.pdf
// max(|xi-xj|+|yi-yj|)
// = max(|zi-zj|,|wi-wj|)
// 変数ごとに独立になった
void solve() {
    int n;
    cin >> n;
    
    vector<int> v, v2;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        int z = x + y, w = x - y;
        v.eb(z);
        v2.eb(w);
    }
    sort(all(v));
    sort(all(v2));
    cout << max(v[sz(v) - 1] - v[0], v2[sz(v2) - 1] - v2[0]) << endl;
}


Measured memory_bytes: 5108
from collections import deque
K = int(input())
G = [[] for i in range(K)]
for i in range(K):
    G[i].append(((10 * i) % K, 0))
    G[i].append(((i + 1) % K, 1))

dist = [float('inf')] * K
dist[1] = 1
que = deque()
que.append(1)

while que:
    n = que.pop()
    for v, c in G[n]:
        if dist[v] > dist[n] + c:
            dist[v] = dist[n] + c
            if c == 0:
                que.append(v)
            else:
                que.appendleft(v)

print(dist[0])


Measured memory_bytes: 35324
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define bp  __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-14;
const int MOD = 1000000007;
int arr[maxn];
int main()
{
    ARB
    ll suf=0,pr=0,n,k,ans=0;
    cin>>n>>k;
    for(ll i=1; i<=n+1; i++)
    {
        pr+=i-1;
        suf+=n+1-i;
        if(i>=k)
            ans+=(suf-pr+1);
        ans%=MOD;
    }
    cout<<ans;
}


Measured memory_bytes: 3668
N,T = map(int,input().split())
lst = []
for i in range(N):
    c,t = map(int,input().split())
    if t <= T:
        lst.append((c,t))
if lst == []:
    print("TLE")
else:
    lst.sort()
    for c,t in lst:
        print(c)
        break

Measured memory_bytes: 3060
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(m)]

ans = []
flag = False

for i in range(m):
    if 1 in a[i]:
        ans.append(a[i][1])
    if n in a[i]:
        ans.append(a[i][0])

if len(set(ans)) != len(ans):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 62580
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n,a[100001]; cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n-1]<<" ";
    int k=0;
    while(2*a[k]<a[n-1]){
        k++;
    }
    if(abs(2*a[k-1]-a[n-1])>abs(2*a[k]-a[n-1])){
        cout<<a[k];
    }else{
        cout<<a[k-1];
    }
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

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

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(string s, string t) {
  sort(ALL(s));
  sort(ALL(t));
  reverse(ALL(t));

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

int main() {
  ios::sync_with_stdio(false);
  string t;
  string s;
  cin >> s;
  cin >> t;
  solve(s, t);
  return 0;
}


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

typedef long long ll;

ll n,l,r,k,arr[200000];

int main()
{
    cin>>n>>k;

    for(int i=0;i<n;i++)
        cin>>arr[i];

    ll mx = *max_element(arr,arr+n);

    l=1,r=mx;
    ll ans=mx;

    while(l<=r)
    {
        ll m = (r+l)/2;

        ll req=0;

        for(int i=0;i<n;i++)
            req += ((arr[i]+m-1)/m) - 1;

        if(req<=k)
        {
            ans = m;
            r = m-1;
        }
        else
            l=m+1;

    }

    // cout<<"A";

    cout<<ans;


}

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

int main(){
  int N; cin >> N;
  vector<int> a( N );
  for( int i = 0; i < N; i++ ) cin >> a[i];
  
  for( int i = 0; i < N; i++ ){
    cout << a[i];
    if( i == N - 1 ) cout << endl;
    else cout << " ";
  }
  
  for( int j = 1; j < N; j++ ){
    int key = a[j];
    int i = j - 1;
    
    while( i >= 0 && a[i] > key ){
      a[i + 1] = a[i];
      i--;
    }
    a[i + 1] = key;
    
    for( int i = 0; i < N; i++ ){
      cout << a[i];
      if( i == N - 1 ) cout << endl;
      else cout << " ";
    }
    
  }
}



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

int main(void) {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x-r>=0 && y-r>=0 && W-x>=r && H-y>=r) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1160
def main():
    H, N = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    dp = [0] * (H+max(A))
    for x in range(1, H+1):
        dp[x] = min(dp[x-a] + b for a, b in zip(A, B))

    print(dp[H])

if __name__ == "__main__":
    main()

Measured memory_bytes: 3444
h, w = map(int, input().split())
grid = [input() for _ in range(h)]
ans = [[0] * w for _ in range(h)]

ans[0][0] = 1
for i, row in enumerate(grid):
    for j, cell in enumerate(row):
        if cell == '#' or (i == 0 and j == 0):
            continue
        elif i == 0:
            ans[i][j] = ans[i][j-1]
        elif j == 0:
            ans[i][j] = ans[i-1][j]
        else:
            ans[i][j] = ans[i][j-1] + ans[i-1][j]
if ans[-1][-1] >= 10**9 + 7:
    ans[-1][-1] %= 10**9 + 7

print(ans[-1][-1])

Measured memory_bytes: 157484
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())
a=[]
for _ in range(M):
    a.append(int(input()))

lst=[None]*(N+1)
def func(n):
    #if n in a:
    #    return 0
    if n<=1:
        return 1
    else:
        if lst[n]:
            return lst[n]
        else:
            temp=(func(n-1)+func(n-2))%(10**9+7)
            lst[n]=temp
            return temp



a=[-1]+a+[N+1]
answer=1
for i in range(M+1):
    if a[i+1]-a[i]==1:
        print(0)
        break
    answer=( func(a[i+1]-a[i]-2)*answer )%(10**9+7)
else:
    print(answer)

Measured memory_bytes: 110832
q=int(raw_input())
for i in range(q):
	a,b=map(int,raw_input().split())
	p=int((a*b-1)**0.5)
	if p*p>a*b-1:
		p=p-1
	r=p*2-1
	if p*p+p>a*b-1:
		r=r-1
	if a==b:
		r=r+1
	print r

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(all(a));
    cout<<a[1]-a[0]+a[2]-a[1]<<endl;
}

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

bool allZero(vector<int> num){
  for(int x : num){
    if(x != 0) return false;
  }
  return true;
}

int getOtherZero(vector<int> num){
  for(int x : num){
    if(x != 0) return x;
  }
  return -1;
}

bool typeOne(vector<int> num){
  int otherZero = getOtherZero(num);
  int cntZero = 0;
  int cntOther = 0;
  for(int x : num){
    if(x==0) cntZero++;
    else if(otherZero == x) cntOther++;
  }

  if(cntZero == num.size()/3 && cntOther == num.size()*2/3) return true;
  return false;
}

bool typeTwo(vector<int> num){

  vector<int> original = num;
  set<int> temp;
  for(int x : num) temp.insert(x);
  if(temp.size() != 3) return false;

  num.clear();
  for(int x : temp) num.push_back(x);

  int a = num[0], b = num[1], c = num[2];
  if((a^b^c) != 0) return false;

  int cntA = 0, cntB = 0, cntC = 0;
  for(int x : original){
    if(x == a) cntA++;
    else if(x == b) cntB++;
    else if(x == c) cntC++;
  }

  return (cntA == original.size()/3 && cntB == original.size()/3 && cntC == original.size()/3);
}

string solve(vector<int> num){
  if(allZero(num)) return "Yes";
  if(num.size()%3 != 0) return "No";
  if(typeOne(num) || typeTwo(num)) return "Yes";
  return "No";
}

int main(){
  int n;
  cin >> n;

  vector<int> num(n);
  for(int i=0; i<n; i++) cin >> num[i];
  cout << solve(num) << endl;
  return 0;
}

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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> L( M );
	vector<int> R( M );
	for( int i = 0; i < M; i++ ) {
		cin >> L[i] >> R[i];
		L[i]--;
		R[i]--;
	}

	vector<int> v( N + 1 );
	for( int i = 0; i < M; i++ ) {
		v[ L[i] ]++;
		v[ R[i] + 1 ]--;
	}
	for( int i = 0; i < N; i++ ) {
		v[i + 1] += v[i];
	}
	int ans = 0;
	for( int i = 0; i < N + 1; i++ ) {
		if( v[i] == M ) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4528
#!/usr/bin/env python3
import sys
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(x: int, a: int, b: int):
    return 'A' if abs(a - x) < abs(b - x) else 'B'


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
#include<cstdio>
#include<iostream>
#include<cstring>
#define INF 100001
using namespace std;

int a[11]={6,9,36,81,216,729,1296,6561,7776,46656,59049};
int v[100001];
int n,_min=999999;

void dfs(int add,int step)   //dfs(0,1);
{
	if(add==n)
	{
		//_min=min(,_min);
		return;
	}
	int i;
	bool flag=false;
	for(i=10;i>=0;i--)
	{
		if(add+a[i]<=n && v[add+a[i]]>step)
		{
			v[add+a[i]]=step;
			flag=true;
			dfs(add+a[i],step+1);
		}
	}
	if(!flag)
	{
		_min=min(_min,v[add]+(n-add));
		
		return;
	}
	return;
}

int main()
{
	int i;
	v[0]=0;	 
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		//printf("\tl\n");
		v[i]=INF;
	}
	//printf("v[1] = %d\n",v[1]);
	dfs(0,1);
	
	if(v[n]==INF)
	{
		printf("%d",_min);
	}
	else
	{
		printf("%d",v[n]);
	}
	return 0;
}


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

using LL  = long long int;

using namespace std;

string S;

string calc(bool flag, int k)
{
  string ret;
  vector<int> vec;
  for (int i = 0; i < 10; i++) {
    vec.push_back(i);
  }

  int N = S.length();
  for (size_t i = 0; i < k; i++) {
    int num = S[i] - '0';

    bool forloop = false;
    for (size_t j = 0; j < vec.size(); j++) {
      if(vec[j] == num){
        forloop = true;
        ret += num + '0';
        vec.erase(vec.begin() + j);
      }
    }

    if(!forloop){
      return "";
    }

  }

  if(k == N){
    return ret;
  }

  int num = S[k] - '0';

  //テ・ツ、ツァテ」ツ?催」ツ??」ツつ?」ツ?、テ」ツ?ョティツソツ妥」ツ??」ツつ?」ツ?、
  if(!flag){
    auto it = upper_bound(vec.begin(), vec.end(), num);

    if(it == vec.end()){
      return "";
    }

    ret += (*it) + '0';
    vec.erase(it);

    for (size_t j = 0; j < vec.size() && ret.length() < N; j++) {
      ret += vec[j] + '0';
    }

    if(ret.length() != N){
      return "";
    }

    return ret;
  }
  //テ・ツーツ湘」ツ?陛」ツ??・ツ・ツエテ」ツ?ョティツソツ妥」ツ??」ツつ?」ツ?、
  else{
    auto it = lower_bound(vec.begin(), vec.end(), num);

    if(it == vec.begin()){
      return "";
    }

    it--;
    ret += (*it) + '0';
    vec.erase(it);

    for (int j = vec.size()-1; 0 <= j && ret.length() < N; j--) {
      ret += vec[j] + '0';
    }

    if(ret.length() != N){
      return "";
    }

    return ret;
  }

  return ret;
}

LL convToLL(string str)
{
  LL ret = 0;
  for (size_t i = 0; i < str.length(); i++) {
    ret *= 10;
    ret += str[i] - '0';
  }
  return ret;
}

string convToString(LL num, int k)
{
  string ret;
  while(num){
    ret += (num % 10) + '0';
    num /= 10;
  }
  while(ret.length() < k){
    ret += '0';
  }

  reverse(begin(ret), end(ret));

  return ret;
}

bool comp(const string &A, const string &B)
{
  if(A == ""){
    return false;
  }
  else if(B == ""){
    return true;
  }
  else{
    LL AA = convToLL(A), BB = convToLL(B);
    LL tmpS = convToLL(S);
    if(min(abs(AA - tmpS), (LL)pow((LL)10, S.length()) - (LL)abs(AA - tmpS)) >
    min(abs(BB - tmpS), (LL)pow((LL)10, S.length()) -(LL)abs(BB - tmpS))){
      return false;
    }
    else if(min(abs(BB - tmpS), (LL)pow((LL)10, S.length()) - (LL)abs(BB - tmpS)) >
  min(abs(AA - tmpS), (LL)pow((LL)10, S.length()) - (LL)abs(AA - tmpS))){
      return true;
    }
    else{
      if(A < B){
        return true;
      }
      else{
        return false;
      }
    }
  }
}

int main()
{
  cin >> S;

  LL tmpS = convToLL(S);

  tmpS -= pow(10, S.length())/2;
  if(tmpS < 0){
    tmpS += pow(10, S.length());
  }

  S = convToString(tmpS, S.length());

  vector<string> ans;
  for (size_t i = 0; i <= S.size(); i++) {
    string tmp = calc(false, i);
    if(tmp != ""){
      ans.push_back(tmp);
    }
    tmp = calc(true, i);
    if(tmp != ""){
      ans.push_back(tmp);
    }
  }

  sort(begin(ans), end(ans), comp);

  cout << ans[0] << endl;

  return 0;
}

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

int main() {
	int a, b,c;
	cin >> a >> b>>c;
	if (a < b &&b< c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	//system("pause");
		return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> d(N);
  for (int i = 0; i < N - 1; i++) {
    d.at(i) = A.at(i+1) - A.at(i);
  }
  d.at(N-1) = K + A.at(0) - A.at(N-1);
  sort(d.begin(), d.end());
  long Ans = 0;
  for (int i = 0; i < N - 1; i++) {
    Ans += d.at(i);
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pll = pair < ll, ll >;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
 
int main(){   
    ll a; cin >> a;
    cout << a + a * a + a * a * a << endl;
}
    

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

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

  for (ll i = 0; i < N; i++) {
    H -= A[i];
  }

  if (H <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (k, ) = [int(e) for e in lines[0].split(' ')]
    (a, b) = [int(e) for e in lines[1].split(' ')]

    return (k, a, b)


def solve(k, a, b):

    result = 'NG'
    for i in range (1, 1001):
        if a <= k * i and k * i <= b:
            result = 'OK'
            break
    
    return  result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

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

long long N,K;
vector<long long> A_posi, A_nega, A_abs;
long long z=0;
long long A_sub;
long long i,j;
long long p,n;
long long val;
long long L,R,M;

void solve_posinega(){
    L=-1000000000000000000;
    R=-1;
    while(1){
        M=(L+R)/2;
        val=0;
        for(i=0; i<p; i++){
            j=upper_bound(A_nega.begin(),A_nega.end(),M/A_posi[i]-(abs(M)%abs(A_posi[i])!=0)) - A_nega.begin();
            val+=(n-j);
        }
        if(L+1==R){
            if(K<=N-val){
                break;
            }else{
                M--;
                break;
            }
        }
        if(K<=N-val){
            R=M;
        }else{
            L=M;
        }
    }
    cout << M << endl;
}

void solve_posiabs(){
    L=1;
    R=1000000000000000000;
    while(1){
        M=(L+R)/2;
        val=0;
        for(i=0; i<p; i++){
            j=upper_bound(A_posi.begin(),A_posi.end(),M/A_posi[i]) - A_posi.begin();
            val+=(p-j);
            if(M<A_posi[i]*A_posi[i]) val--;
        }
        for(i=0; i<n; i++){
            j=upper_bound(A_abs.begin(),A_abs.end(),M/A_abs[i]) - A_abs.begin();
            val+=(n-j);
            if(M<A_abs[i]*A_abs[i]) val--;
        }
        val/=2;
        if(L+1==R){
            if(K<=N-val){
                break;
            }else{
                M++;
                break;
            }
        }
        if(K<=N-val){
            R=M;
        }else{
            L=M;
        }
    }
    cout << M << endl;
}

int main(){
    //input
    cin >> N >> K;
    for(i=0; i<N; i++){
        cin >> A_sub;
        if(A_sub>0){
            A_posi.push_back(A_sub);
        }else if(A_sub<0){
            A_nega.push_back(A_sub);
            A_abs.push_back(-A_sub);
        }else{
            z++;
        }
    }

    //calc&output
    sort(A_posi.begin(),A_posi.end());
    sort(A_nega.begin(),A_nega.end());
    sort(A_abs.begin(),A_abs.end());
    p=A_posi.size();
    n=A_nega.size();
    if(K<=p*n){
        N=p*n;
        solve_posinega();
    }else if((K-p*n)<=z*(p+n)+(z*(z-1)/2)){
        cout << 0 << endl;
    }else{
        N=(p*(p-1))/2+(n*(n-1))/2;
        K-=p*n;
        K-=(z*(p+n)+(z*(z-1))/2);
        solve_posiabs();
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 6264
A,B,K=map(int,input().split())
for i in range(K):
    if i%2==0:
        if A%2==1:
            A-=1
        B+=int(A/2)
        A=int(A/2)
    else:
        if B%2==1:
            B-=1
        A+=int(B/2)
        B=int(B/2)
print(A,B)

Measured memory_bytes: 3060
#include <stdio.h>

int v[212345];

int main(){
    int n;
    long long resposta, total = 0;
    scanf("%d", &n);
    int v[n];
    for (int i = 0; i < n; i++){
        scanf("%d", &v[i]);
        total += v[i];
    }
    long long rogerio = total, mathias = 0, diferenca;
    for (int i = 0; i <= n-2; ++i){
        mathias += v[i];
        rogerio -= v[i];
        diferenca = mathias - rogerio;
        if (diferenca < 0)
            diferenca *= -1;
        if (i == 0 || (i != 0 && resposta > diferenca))
            resposta = diferenca;
    }
    printf("%lld\n", resposta);
    return 0;
}

Measured memory_bytes: 896
#include <stdint.h>

#include <iostream>

using namespace std;

int64_t Gcd(int64_t a, int64_t b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}

int64_t Lcm(int64_t a, int64_t b) { return a / Gcd(a, b) * b; }

int main(void) {
  int64_t A, B;
  cin >> A >> B;
  cout << Lcm(A, B) << endl;
}


Measured memory_bytes: 3632
use strict;
use warnings;
use feature 'say';
use Data::Dumper;
sub get { my $input = <>; chomp($input); $input }

my $n = get;
my $s = [map {[split //, get]} 1..$n];

$_ = join("", sort @$_) for @$s;
@$s = sort {$a cmp $b} @$s;

my $group = {};
$group->{$_}++ for @$s;

my $total_count = 0;
for my $count (values %$group) {
    $total_count += $_ for 1..$count-1;
}

say $total_count;

Measured memory_bytes: 105712
#include<bits/stdc++.h>
using namespace std;
int a,b,s;
char c;
int main()
{
    cin>>a;
    for(int i=0; i<a; i++)
    {
        cin>>c;
        if(c=='I')
		{
	    	b++;
		}
        else b--;
        s=max(s,b);
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::collections::HashMap;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    let t: i32 = sc.read();
    let mut map: HashMap<i32, i32> = HashMap::new();

    for _i in 0..n {
        map.insert(sc.read(), sc.read());
    }

    //for (k, v) in &map {
    //    println!("{} {}", k, v)
    //}

    let mut cost = 1000;
    let mut tle = true;
    for (k, v) in map {
        if v <= t {
            cost = std::cmp::min(k, cost);
            tle = false;
        }
    }

    if tle {
        println!("TLE");
    } else {
        println!("{}", cost);
    }
}



Measured memory_bytes: 4352
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
signed main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[21][21]={};
  cin >> n;
  ll dp[1<<n]={};
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      cin >> a[i][j];
    }
  }
  dp[0]=1;
  for(int i=0; i<(1<<n); i++) {
    int cnt=__builtin_popcount(i);
    for(int j=0; j<n; j++) {
      if((i&(1<<j))&&a[cnt-1][j]) {
        (dp[i]+=dp[i^(1<<j)])%=MOD;
      }
    }
  }
  cout << dp[(1<<n)-1] << "\n";
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() 
{
  int n, min, A[200], ans[200] = {};
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> A[i];

  for(int i = 0; i < n; i++)
  {
    if(A[i]%2 == 0) 
    {
      A[i] /= 2;
      ans[i]++;
      i--;
    }
  }
  min = ans[0];
  for(int i = 1; i < n; i++)
    if(min > ans[i]) min = ans[i];

  cout << min << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
	double x,a,b;
	scanf("%lld %lld %lld",&x,&a,&b);
	if(a<b)
	{
		if(x>a&&x<b)
		{
			double p=x-a;
			double q=b-x;
			if(p>q)
			{
				printf("B\n");
			}
			else
			{
				printf("A\n");
			}
		}
		if(x<a)
		{
			printf("A\n");
		}
		if(x>b)
		{
			printf("B\n");
		}
	}
	else
	{
		if(x>b&&x<a)
		{
			double p=x-b;
			double q=a-x;
			if(p>q)
			{
				printf("A\n");
			}
			else
			{
				printf("B\n");
			}
		}
		if(x>a)
		{
			printf("A\n");
		}
		if(x<b)
		{
			printf("B\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
//テンプレート
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(){
    int N,M,C,i,j,ans=0,count=0;
    scanf("%d%d%d",&N,&M,&C);
    int A[N][M],B[M];
    for (i=0; i<M; i++) {
        scanf("%d",&B[i]);
    }
    for (i=0; i<N; i++) {
        for (j=0; j<M; j++) {
            scanf("%d",&A[i][j]);
        }
    }
    //入力ここまで
    
    for (i=0; i<N; i++) {
        for (j=0; j<M; j++) {
            ans += B[j] * A[i][j];
        }
        ans+=C;
        if (ans>0) {
            count++;
        }
        ans=0;
    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n, c;
Int dp[220000];
Int h[220000];

Int calc(P f, Int x){
    return f.first * x + f.second;
}

struct CHTrick{
    vector<Int> to;
    vector<P> f;

    CHTrick(){}

    void add_line(Int a, Int b){
        P new_f = P(a, b);
        if(f.empty()){
            f.push_back(new_f);
            return;
        }
        if(calc(new_f, INF) >= calc(f.back(), INF))return;
        if(calc(new_f, -INF) <= calc(f.front(), -INF)){
            f.clear();
            to.clear();
            f.push_back(new_f);
            return;
        }

        while(!to.empty()){
            int lastl = to.back() + 1;
            if(calc(new_f, lastl) <= calc(f.back(), lastl)){
                f.pop_back();
                to.pop_back();
            }
            else break;                
        }

        int bottom;
        if(to.empty())bottom = -INF;
        else bottom = to.back() + 1; //f.back();
        int top = INF;//new_f

        while(top - bottom > 1){
            int mid = (top + bottom) / 2;
            if(calc(new_f, mid) <= calc(f.back(), mid))top = mid;
            else bottom = mid;
        }
        to.push_back(bottom);
        f.push_back(new_f);
    }
    
    Int get_min(int x){
        Int ind = lower_bound(to.begin(), to.end(), x) - to.begin();
        return calc(f[ind], x);
    }
};

int main(){
    cin >> n >> c;
    for(int i = 0;i < n;i++)cin >> h[i];
    CHTrick ch;
    
    dp[0] = 0;
    ch.add_line(-2*h[0], dp[0] + h[0] * h[0]);
    for(int i = 1;i < n;i++){
        dp[i] = ch.get_min(h[i]) + h[i] * h[i] + c;
        ch.add_line(-2*h[i], dp[i] + h[i] * h[i]);
    }
    cout << dp[n-1] << endl;    
    return 0;
}

Measured memory_bytes: 10992
#include <iostream>
#include <algorithm>
#include <vector>

#define pb push_back
#define nmax 200010
#define MOD 1000000007
#define SZ(x) ((int)(x.size()))

using namespace std;

typedef long long int ll;

int n;
vector <int> graph[nmax];

int dp[2][nmax]; // 0 black, 1 white

void dfs(int node, int p = 0)
{
	dp[0][node] = dp[1][node] = 1;

	for (int i = 0; i < SZ(graph[node]); i++)
		if (graph[node][i] != p) {

			dfs(graph[node][i], node);

			dp[0][node] = (1LL * dp[0][node] * dp[1][graph[node][i]]) % MOD;
			dp[1][node] = (1LL * dp[1][node] * ((dp[0][graph[node][i]] + dp[1][graph[node][i]]) % MOD)) % MOD;
		}
}

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

	for (int i = 1; i < n; i++) {

		int x, y;

		scanf("%d %d", &x, &y);

		graph[x].pb(y);
		graph[y].pb(x);
	}

	dfs(1);

	printf("%d", (dp[0][1] + dp[1][1]) % MOD);

	return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

vi sub;
int ans;

void solve(string st);

signed main()
{
    string s;
    cin >> s;
    solve(s);
    cout << ans << endl;

    return 0;
}

void solve(string st)
{
    if (!st.size()) {
        for (int i:sub) ans += i;
        return;
    }
    Rep(i, st.size()+1) {
        sub.pb(stoll(st.substr(0, i)));
        solve(st.substr(i));
        sub.pop_back();
    }
}




Measured memory_bytes: 256