akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define endl "\n"
    #define sz(x) (int)(x).size()
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
/*.....................................................................................................................*/

    ll mod =(ll)1e9+7;
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
    long long binpow(long long x, long long p) 
    {
        if (p == 0) return 1;
    	if (p == 2 || (p & 1)) return mult(x, binpow(x, p - 1));
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
    // bool check(ll x){}
    ll binsearch(ll l,ll r)
    {
        while(l<r)
        {
            ll mid=(l+r)/2;
            // if(check(mid))r=mid;
            // else l=mid+1;
        }
        return l;
    }
    const ll man=(ll)1005;
    vector<ll>adj[man];
    bool vis[man][man];
    ll d[man],depth[man],par[man];
    void addedge(ll u,ll v){adj[u].pb(v);adj[v].pb(u);}
    ll dx[4]={1,-1,0,0};ll dy[4]={0,0,1,-1};
/*........................................................................................................................*/

signed main()/*Check flow...question galat mat padhna */
{
    fast;  
    ll x,n;
    cin>>x>>n;
    set<ll>a;
    For(i,n)
    {
        read(y);
        a.insert(y);
    }
    ll cnt=0;
    while(true)
    {
        if(a.find(x-cnt)==a.end())
        {
            cout<<x-cnt<<endl;
            return 0;
        }
        if(a.find(x+cnt)==a.end())
        {
            cout<<x+cnt<<endl;
            return 0;
        }
        cnt++;
    }
}      


Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

bool is_prime(ll x) {
	for (ll i = 2; i*i <= x; i++)
		if (x % i == 0) return false;
	return true;
}

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

	ll ans = 1;
	for (int i = 2; i <= N; i++) {
		if (is_prime((ll)i)) {
			int NN = N;
			int cnt = 0;
			while (NN) {
				cnt += NN/i;
				NN /= i;
			}
			ans *= cnt+1;
			ans %= mod;
		}
	}

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


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a=0;
  int W,H,x,y,r=0;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x-r>=0&&x+r<=W){
    if(y-r>=0&&y+r<=H){
      a=1;
    }
  }
  else{
    a=0;
  }
  if(a==1){
    printf("Yes\n");
  }
  else if(a==0){
    printf("No\n");
  }
  return 0;
}
 

 

Measured memory_bytes: 584
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  
  if(r<=x && x<=W-r && r<=y && y<=H-r)printf("Yes\n");
  else printf("No\n");

  return 0;
}

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

namespace RedOrBlue
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetInput();
            Console.WriteLine((input.Count(c=>c=='R') > input.Count(c=>c=='B') ? "Yes" : "No"));
        }

        static string GetInput()
        {
            Console.ReadLine();
            return Console.ReadLine();
        }

    }
}


Measured memory_bytes: 11220
#include <iostream>
using namespace std;
int a[1000000];
int b[1000000];
int ind[1000000];
int main(){
    int n, mx = 0;
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        ind[a[i]] = i;
    }
    for(int i = 1; i <= n; i ++){
        b[i] = ind[i-1] < ind[i] ? b[i-1] + 1 : 1;
        if(b[i] > mx) mx = b[i];
    }
    cout << n - mx << endl;
    return 0;
}


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

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  if(A>=B){
    cout << "delicious" << endl;
    return 0;
  }
  if(A+X<B){
    cout << "dangerous" << endl;
    return 0;
  }
   cout << "safe" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,c;
  vector<int> a,b;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c;
    b.push_back(c);
  }
  for(int i=0;i<n;i++){
    for(int j=b.size()-1;j>=0;j--){
      if(b[j]==j+1){
	a.push_back(b[j]);
	b.erase(b.begin()+j);
	break;
      }
    }
  }
  if(b.size()!=0) cout<<-1<<"\n";
  else{
    for(int i=a.size()-1;i>=0;i--){
      cout<<a[i]<<"\n";
    }
  }
  return 0;
}
      


Measured memory_bytes: 3652
#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, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b) {
        REP(i, a) {
            cout << b;
        }
        cout << endl;
    } else {
        REP(i, b) {
            cout << a;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }


const int inf = 1e9;
const int maxn = 50;
LL N, A[maxn], pw[maxn];

void dfs(const LL x)
{
    if (x == 0)
        return;
    LL i,j, y = 0;
    if (x > 0) {
        i = j = 0;
        while (y < x) {
            j = i; y += pw[i]; i += 2;
        }
    }
    else {
        i = j = 1;  
        while (y > x) {
            j = i; y += pw[i]; i += 2 ;
        }
    }
    A[j] = 1;
    dfs(x-pw[j]);
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> N) {
        if (N == 0) {
            cout << 0 << endl;
            continue;
        }
        pw[0] = 1;
        FOR(i,1,33) {
            pw[i] = pw[i-1]* (-2);
        }
        memset(A,0,sizeof(A));
        dfs(N);
        int i = maxn-1;
        while (A[i] == 0)
            i--;
        reverse(A,A+i+1);
        FOR(j,0,i+1)
            cout << A[j];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
k, n = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

max_len = 0
for i in range(len(A) - 1):
  if max_len < A[i + 1] - A[i]:
    max_len = A[i + 1] - A[i]

# A[n] -> A[0]
l = (k - A[-1]) + A[0]
if max_len < l:
  max_len = l

print(k - max_len)


Measured memory_bytes: 31516
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#define base 10000
#define maxn 100
using namespace std;
int main()
{

    int n,k;
    scanf("%d%d",&n,&k);
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        if(ans>k)
            ans+=k;
        else
            ans*=2;
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    auto prime = [](int m){
        vector<pair<int,int>> v;
        for(int i=2;i*i<=m;++i)if(m%i == 0){
            int count = 0;
            while(m%i == 0)m/=i,count++;
            v.push_back({i,count});
        }
        if(m != 1)v.push_back({m,1});
        return v;
    };
    int n,m;
    cin>>n>>m;
    auto p = prime(m);
    ll ret = 1ll;
    
    for(int i=0;i<(int)p.size();++i){
        ret *= comb(p[i].second+n-1,n-1);
        ret %= mo;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 12996
#include<stdio.h>

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

        int mp[w][h];
        for(int i=0; i<w*h; i++) mp[i/h][i%h]=1;

        for(int i=0; i<n; i++){
                int x, y, a;
                scanf("%d %d %d", &x, &y, &a);
                switch(a){
                        case 1:
                                for(int j=0; j<x*h; j++) mp[j/h][j%h]=0;
                                break;
                        case 2:
                                for(int j=x*h; j<w*h; j++) mp[j/h][j%h]=0;
                                break;
                        case 3:
                                for(int j=0; j<w*y; j++) mp[j%w][j/w]=0;
                                break;
                        case 4:
                                for(int j=w*y; j<w*h; j++) mp[j%w][j/w]=0;
                                break;
                }
        }

        //for(int i=0; i<w; i++){for(int j=0; j<h; j++)printf("%d ", mp[i][j]);puts("");}

        int sm = 0;
        for(int i=0; i<w*h; i++) sm += mp[i/h][i%h];
        printf("%d\n", sm);
        return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [u64; n],
  }
  let all_xor = a.iter().fold(0, |acc, x| acc ^ x);
  let mut a: Vec<_> = a.into_iter().map(|x| x & ! all_xor).collect();

  for rank in (0 .. 60).rev() {
    let (xi, x) = match a.iter().enumerate().find(|&(_, &x)| (x >> rank) & 1 == 1 && x < 1 << (rank + 1)) {
      None => continue,
      Some((xi, &x)) => (xi, x),
    };
    for i in 0 .. n {
      if i != xi && (a[i] >> rank) & 1 == 1 {
        a[i] ^= x;
      }
    }
  }
  let ans = all_xor + 2 * a.iter().fold(0, |acc, x| acc ^ x);

  puts!("{}\n", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
#define EN cout<<endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;



int main() {
    ll n,ans=0,a;
    string s;
    cin>>n;
    rep(i,n){
        a=i+1;
        if(a%5!=0&&a%3!=0)ans+=a;
    }
     cout<<ans<<endl;
}


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

int par[100], rank[100];

void init( int n )
{
	for( int i = 0; i != n; ++i )
	{
		par[i] = i;
		rank[i] = 0;
	}

	return;
}

int find( int x )
{
	if( par[x] == x )
		return x;
	else
		return par[x] = find( par[x] );
}

void unite( int x, int y )
{
	x = find( x );
	y = find( y );

	if( x == y )
		return;

	if( rank[x] < rank[y] )
		par[x] = y;
	else
	{
		par[y] = x;
		if( rank[x] == rank[y] )
			++rank[x];
	}

	return;
}

bool same( int x, int y )
{
	return find( x ) == find( y );
}

struct edge{ int from, to, cost; };

int n, m;
std::vector<edge> es;

int main()
{
	while( std::cin >> n >> m, n | m )
	{
		es.clear();

		for( int i = 0; i != m; ++i )
		{
			int a, b, cost;
			std::cin >> a >> b >> cost;
			edge e = { a, b, cost };
			es.push_back( e );
		}

		std::sort( es.begin(), es.end(), []( const edge& e1, const edge& e2 ){ return e1.cost < e2.cost; } );

		init( n );

		int ans = 0;
		for( int i = 0; i != m; ++i )
		{
			if( !same( es[i].from, es[i].to ) )
			{
				ans += es[i].cost;
				unite( es[i].from, es[i].to );
			}
		}

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

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <string>

using namespace std;

#pragma GCC oprimize("Ofast")
#define rep(i,a,b) for(__typeof(b)i=a;i<b;++i)
#define fs first
#define sc second
#define pb emplace_back

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
typedef pair<ll,ll> pl;

const ll inf = ~((ll)1<<(ll)63);


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

    string s;
    ll h,w;
    cin >> h >> w;
    vl2 grid(h,vl(w));
    vl2 xs(h,vl(w));
    vl2 ys(h,vl(w));
    rep(k,0,h)
    {
        ll start=0;
        rep(i,0,w)
        {
            char c;
            cin >> c;
            grid[k][i] = c;
            if(c == '#')
            {
                rep(j,start,i)
                {
                    xs[k][j] = i-start;
                }
                xs[k][i]=0;
                start = i+1;
            }
            else if(c=='.'&&i==w-1)
            {
                rep(j,start,i+1)
                {
                    xs[k][j] = i+1-start;
                }
                start = i+1;
            }
        }
    }

    rep(k,0,w)
    {
        ll start=0;
        rep(i,0,h)
        {
            if(grid[i][k] == '#')
            {
                rep(j,start,i)
                {
                    ys[j][k] = i-start;
                }
                ys[i][k]=0;
                start = i+1;
            }
            else if(grid[i][k]=='.'&&i==h-1)
            {
                rep(j,start,i+1)
                {
                    ys[j][k] = i+1-start;
                }
                start = i+1;
            }
        }
    }

    ll ans = 0;
    rep(i,0,h)
    {
        rep(j,0,w)
        {
            ans = max(ans,xs[i][j] + ys[i][j]);
        }
    }

    cout << ans-1;

	return 0;
}


Measured memory_bytes: 94208
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int n;
string s;

bool ok(int len)
{
    bool ret = false;
    map<string, int> m;
    for (int i = 0; i <= n - len; ++i)
    {
        string t = s.substr(i, len);
        if (m[t] == 0)
        {
            m[t] = i + 1 + len;
        }
        else if (m[t] <= i + 1)
        {
            ret = true;
        }
    }
    return ret;
}

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

    cin >> n;
    cin >> s;

    int  l = 0, r = n / 2 + 1;
    while (l + 1 < r)
    {
        int m = (l + r) / 2;
        if (ok(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }

    cout << l << "\n";
    return 0;
}



Measured memory_bytes: 6656
e1,e2,e3,e4=map(int,input().split())# Your code here=map(int,input().split())
if e1==e2 and e3==e4:
    print('yes')
elif    e1==e3 and e2==e4:
    print('yes')
elif    e1==e4 and e2==e3:
    print('yes')
else:
    print('no')


Measured memory_bytes: 5596
#include<stdio.h>
#include<string.h>
#define N 100005

typedef struct pp{
  char name[100];
  int t;
}Pin;

Pin Q[N+1],a[N+1];
int head=0, tail=0, n;

void enque(Pin x){
 Q[tail]=x;
  if(tail+1==N){
    tail=0;
  }
  else tail++;
}

Pin deque(){
 Pin x;
  x=Q[head];
    if(head+1==N){
      head=0;
    }
    else{
      head++;
    }
  return x;
}


int main(){
  int a = 0, c;
  int i, q,j=0;
  Pin u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enque(Q[i]);
  }

  while(j!=n){
    u=deque();
    if(u.t<=q){
      a+=u.t;
     printf("%s %d\n",u.name,a);
     j++;
    }
    else {
	u.t-=q;
	a+=q;
	enque(u);

	  }
  }
  return 0;
}

Measured memory_bytes: 10832
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 22 04:19:50 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]
d = [False]*8
count = 0
ans = 0
for a in A:
    if a//400 >= 8:
        count += 1
    else:
        if d[a//400] == False:
            ans += 1
            d[a//400] = True

if count == 0:
    print(ans,ans)
else:
    if ans == 0:
        print(1,count)
    else:
        print(ans,ans+count)

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

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

  int ans=0;

  ans+= (X / 500) * 1000;
  X %= 500;

  ans+= (X /5) * 5;
  cout << ans;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    ll h,w;
    cin >> h >> w;
    if(h==1 || w==1){
        cout << 1 << endl;
        return 0;
    }
    ll a = (w+1)/2;
    ll b = w/2;
    ll ans = a*((h+1)/2) + b*(h/2);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

int dp[50][50];

int bt(int x,int y) {
	if(x < 2 && y < 2)
		return dp[x][y] = 0;
	if(dp[x][y] != -1)
		return dp[x][y];
	set<int> to;
	for(int i = 1;i*2 <= max(x,y);i++) {
		if(i*2 <= x) {
			to.insert(bt(x-2*i,y+i));
		}
		if(i*2 <= y) {
			to.insert(bt(x+i,y-2*i));
		}
	}
	dp[x][y] = 0;
	while(to.count(dp[x][y]))
		dp[x][y]++;
	return dp[x][y];
}

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

//	memset(dp,-1,sizeof dp);
//	for(int i = 0;i <= 20;i++) {
//		for(int j = 0;j <= 20;j++) {
//			cout<<bt(i,j)<<" \n"[j == 20];
//		}
//	}

	{
		long long x,y;
		cin>>x>>y;
		y -= (x-1);
		if(y >= 0 && y < 3) {
			cout<<"Brown\n";
		} else {
			cout<<"Alice\n";
		}
	}
	return 0;
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll H, W, dp[1010][1010];
  bool as[1010][1010];

  void init() {
    scanf("%lld %lld", &H, &W);
    char a;
    rep(i, H) rep(j, W) {
      cin >> a;
      if(a=='.') as[i][j] = true;
    }
  }

  void solve() {
    rep(i, H) rep(j, W) if(as[i][j]) {
      if(i==0&&j==0) dp[i+1][j+1] = 1;
      else dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j];
      dp[i+1][j+1] %= MOD_1_000_000_007;
    }
    cout << dp[H][W] << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 9088
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if(n%111==0){
        cout << n;
    }
    else{
        cout << (n/111 + 1)*111;
    }


    return 0;
}

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

int main(){
    int ans=0,sum=0;
    int a,b,k;
    cin >>a>>b;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << (n-1)*(m-1) << endl;

    if((a+b)%2==0)cout << (a+b)/2 <<endl;
    else cout << "IMPOSSIBLE" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    bool j = true;
    while(j) {
        int a,b;
        char op;
        cin >> a>> op >> b;
        if (op=='?') {
            return 0;
        }
        if (op=='+') {
            ct(a+b);
        }
        if (op=='*') {
            ct(a*b);
        }
        if (op=='/') {
            ct(a/b);
        }
        if (op=='-') {
            ct(a-b);
        }
    }
}


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

int main(){
  int r;
  int D;
  int x0;
  int x1,x2,x3,x4,x5,x6,x7,x8,x9,x10;
  cin >> r >> D >> x0;
  x1 = r*x0-D;
  x2 = r*x1-D;
  x3 = r*x2-D;
  x4 = r*x3-D;
  x5 = r*x4-D;
  x6 = r*x5-D;
  x7 = r*x6-D;
  x8 = r*x7-D;
  x9 = r*x8-D;
  x10 = r*x9-D;
  cout << x1<< endl;
  cout << x2 << endl;
  cout << x3 << endl;
  cout << x4 << endl;
  cout << x5 << endl;
  cout << x6 << endl;
  cout << x7 << endl;
  cout << x8 << endl;
  cout << x9 << endl;
  cout << x10 << endl;
}

Measured memory_bytes: 256
import sys

a = input()
b = input()
c = input()
d = input()
e = input()
tmp = [a,b,c,d,e]
l = [int(a[-1]),int(b[-1]),int(c[-1]),int(d[-1]),int(e[-1])]

minimum = 10
num = 0
for i in range(5):
	if minimum > l[i] and l[i] != 0:
		minimum = l[i]
		num = i

ans = 0
for i in range(5):
	if i != num:
		if l[i] != 0:
			add = 10 - l[i]
		else:
			add = 0
		ans += int(tmp[i]) + add

ans += int(tmp[num])
print(ans)


Measured memory_bytes: 3064
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

K=gets.to_i
K.times do
    print "ACL"
end
print "\n"

Measured memory_bytes: 14184
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <climits>
#include <bitset>
#include <fstream>
#include <algorithm>
#include <functional>
#include <stack>
#include <string>
#include <cmath>
#define fi first
#define se second
#define re register
#define ls i << 1
#define rs i << 1 | 1
#define pb push_back
#define pii pair<int,int>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

#define int long long

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
int tt;
inline int rd(){
  int x = 0, f = 1; char ch = getchar();
  while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
  while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}

void out(int a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) out(a / 10);
  putchar(a % 10 + '0');
}

void solve() {
  int x = rd();
  puts(x < 30 ? "No" : "Yes");
}

signed main(){
//  for (tt = rd(); tt--; )
  solve();
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int n; cin >> n;
    if(n < 1000){
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
}

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

ll F(ll a){
    ll res=0;
    while(a>0){
        res+=a%10;
        a/=10;
    }
    return res;
}

double S(ll a){
    double res=(double)a/F(a);
    return res;
}

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

    vector<ll> res;
    ll base=1;
    rep(i,0,15){
        rep(j,1,140){
            res.push_back(base*(j+1)-1);
        }
        base*=10;
    }
    sort(res.begin(),res.end());
    res.erase(unique(res.begin(), res.end()), res.end());

    rep(i,0,res.size()){
        rep(j,i+1,res.size()){
            if(S(res[i])>S(res[j])){
                res.erase(res.begin()+i--);
                break;
            }
        }
    }

    rep(i,0,k){
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 256
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0
for x in a:
    if x%2==0:
        even+=1
    else:
        odd+=1
if p==0:
    print(2**even*max(1,2**(odd-1)))
else:
    print(2**even*(2**odd-max(2**(odd-1),1)))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;
ll memo[105][100005];
ll w[105];
ll v[105];
int init(){
    for(int i = 0; i < 105; i++){
        for(int j = 0; j < 100005; j++){
            if(j == 0){
                memo[i][j] = 0;
            }else{
                memo[i][j] = 0;
            }
        }
        w[i] = 0;
        v[i] = 0;
    }
}



ll solve(ll index,ll weight){
    if(memo[index][weight] != -1){
        return memo[index][weight];
    }
    ll M = solve(index - 1,weight);
    for(int wi = 0; wi <= weight; wi++){
        if(wi - w[index] < 0)continue;
        M = max(M,solve(index - 1,wi - w[index]) + v[index]);
    }
    memo[index][weight] = M;
    return memo[index][weight];
}


int main() {
    init();
    ll N,W;
    cin >> N >> W;
    for(ll i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }
    for(int ni = 1; ni <= N; ni++){
        for(int wi = 0; wi <= W; wi++){
            memo[ni][wi] = max((wi - w[ni - 1] < 0 )? 0 : memo[ni - 1][wi - w[ni - 1]] + v[ni - 1],memo[ni - 1][wi]);
        }
    }
    cout << memo[N][W] << endl;
}


Measured memory_bytes: 82304
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m
    integer(int32), allocatable:: a(:)

    read*, n,m
    allocate(a(m))
    read*, a(:)

    if (n < sum(a)) then
        print*, -1
    else
        print'(i0)', n - sum(a)
    end if
end program name

Measured memory_bytes: 2948
#include <stdio.h>
#include <string.h>

int main() {
    char instr[100001];
    char lowers[] = "abcdefghijklmnopqrstuvwxyz";
    scanf("%100000s", instr);


    int i, j;
    int len = strlen(instr);
    int flag;
    for (i = 0; i < 26; i++) {
	flag = 0;
	for (j = 0; j < len; j++) {
	    if (lowers[i] == instr[j]) {
		flag = 1;
		break;
	    }
	}
	if (flag == 0) {
	    printf("%c\n", lowers[i]);
	    return 0;
	}
    }

    puts("None");
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    N = ri()
    s = []
    t = []
    for i in range(N):
        x, y = input().split()
        s.append(x)
        t.append(int(y))
    X = rs()
    a = sum(t)
    b = 0
    for x, y in zip(s, t):
        b += y
        if x == X:
            break
    print(a - b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9044
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}

ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


string Toupper(string s){
  string ans="";
  rep(i,s.size()){
    if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
    else ans+=s[i];
  }
  return ans;
}
string Tolower(string s){
  string ans="";
  rep(i,s.size()){
    if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
    else ans+=s[i];
  }
  return ans;
}


const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*bool cmp(pint a, pint b) { return a.second < b.second; }*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll ans=1e15;
  rep(i,100001) chmin(ans,2*c*i+a*max((x-i),(ll)0)+b*max((y-i),(ll)0));
  cout<<ans<<endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<double> R(n),X(n);
    for(int i=0;i<n;i++){
        cin>>R[i];
        X[i]=R[i];
        for(int j=0;j<i;j++){
            X[i]=max(X[i],X[j]+2*sqrt(R[i]*R[j]));
        }
        // cout<<X[i]<<endl;
    }
    double ans = 0;
    for(int i=0;i<n;i++) ans = max(ans,X[i]+R[i]);
    cout<<fixed;
    cout.precision(8);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3268
#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 pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}






int main() {
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort (a,a+3);
    cout << (a[0]*a[1])*(a[2]%2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int x[n];
	int s=1;
	int xmin=0;
	for(int i=0;i<n;i++){
		cin>>x[i];
		if(i==0) xmin=x[i];
	}
	for(int i=1;i<n;i++){
		if(x[i]>=xmin){
			xmin=x[i];
			s++;
		}
	}
	cout<<s<<"\n";
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main()
{
  char code[17]="CODEFESTIVAL2016";
  char tmpcode[17]={0};
  int i,count=0;
  scanf("%s",tmpcode);
  for(i=0;i<17;i++){
    if(tmpcode[i]!=code[i])count++;
  }

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

  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

/* template end */
const int limit = 11729;
string dp[limit];
int match[10] = {-INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

  int n, m;
  cin >> n >> m;

  vector<pair<int, string>> al(m);
  REP(i, m) {
    int t;
    cin >> t;
    al[i] = mp(t, to_string(t));
  }
  sort(al.begin(), al.end(), [](auto a, auto b) { return b.first > a.first; });
  REP(i, limit) {
    dp[i] = "";
  }
  REP(i, n) {
    if(i>0 && dp[i].size() ==0) { 
      continue; 
    }
    for (auto j : al) {
      int idx = i + match[j.first];
      dp[idx] = [&](string s, string t) {
        if (t.size() > s.size() || t > s) {
          return t;
        }
        return s;
      }(dp[idx], dp[i] + j.second);
    }
  }

  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 43776
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 

const ll mod = 1e9+7;
const ll inf=1e18+1e17;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}

const ll N=2e5+6;
ll arr[N],brr[N];
ll dp[N],ans[N];
vii tree[N];
int n;
void dfa( int pos, int par){
	brr[pos]=1;
	for ( int i: tree[pos])
		if ( i!=par){
			dfa(i,pos);
			brr[pos]+=brr[i];
		}
}
void dfs( int pos, int par){
	ll aa=0,bb=0;
	for ( int i: tree[pos])
		if ( i!=par){
			bb+=aa*brr[i];
			aa=aa+brr[i];
		}
	bb=bb+(n-dp[arr[pos]]-aa-1)*aa+n-dp[arr[pos]];
	ans[arr[pos]]+=bb;
	ll val=dp[arr[pos]];
	for ( int i: tree[pos])
		if ( i!=par){
			dp[arr[pos]]=n-brr[i];
			dfs(i,pos);
		}
	dp[arr[pos]]=val+aa+1;
}
void solve(){
	
	cin>>n;
	memset( dp,0,sizeof ( dp));
	memset( ans,0,sizeof ( ans));
	for (int i=1;i<=n;i++)
		cin>>arr[i];
	for (int i=0;i<n-1;i++){
		int aa,bb;
		cin>>aa>>bb;
		tree[aa].pb( bb) ;
		tree[bb].pb( aa);
	}
	dfa(1,0);
	dfs(1,0);
	for ( int i=1;i<=n;i++)
		cout<<ans[i]<<'\n';
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll t=1;
//	cin>>t;
    for (int i=1;i<=t;i++){
    //	cout<<"Case #"<<i<<": ";
    	solve();
 	}
}





Measured memory_bytes: 36312
#include <stdio.h>
#include <string.h>

void reverse(char str[]);

int main(void)
{
  char turn = 'a';
  char a[200],b[200],c[200];
  int alen,blen,clen;

  scanf("%s",a);
  scanf("%s",b);
  scanf("%s",c);

  reverse(a);
  reverse(b);
  reverse(c);

  alen = strlen(a);
  blen = strlen(b);
  clen = strlen(c);

  while(1)
    {
      alen = strlen(a);
      blen = strlen(b);
      clen = strlen(c);
 if(turn == 'a')
        {
          if(alen == 0)
            {
              printf("A\n");
              break;
            }

          else if(a[alen - 1] == 'a')
            {
              a[alen - 1] = '\0';
              turn = 'a';
            }
          else if(a[alen - 1] == 'b')
            {
              a[alen - 1] = '\0';
              turn = 'b';
            }
          else if(a[alen - 1] == 'c')
            {
              a[alen - 1] = '\0';
              turn = 'c';
            }
        }
 if(turn == 'b')
        {
          if(blen == 0)
            {
              printf("B\n");
              break;
            }

          else if(b[blen - 1] == 'a')
            {
              b[blen - 1] = '\0';
              turn = 'a';
            }
          else if(b[blen - 1] == 'b')
            {
              b[blen - 1] = '\0';
              turn = 'b';
            }
          else if(b[blen - 1] == 'c')
            {
              b[blen - 1] = '\0';
              turn = 'c';
            }
        }
 if(turn == 'c')
        {
          if(clen == 0)
            {
              printf("C\n");
              break;
            }

          else if(c[clen - 1] == 'a')
            {
              c[clen - 1] = '\0';
              turn = 'a';
            }
          else if(c[clen - 1] == 'b')
            {
              c[clen - 1] = '\0';
              turn = 'b';
            }
          else if(c[clen - 1] == 'c')
            {
              c[clen - 1] = '\0';
              turn = 'c';
            }
        }

    }

  return 0;
}

void reverse(char str[])
{
  int i,len;
  char cpy[200];
  strcpy(cpy,str);

  len = strlen(str);

  for(i = 0;i < len;i++)
    str[i] = cpy[len - i - 1];

  str[len] = '\0';
}


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

int main(){
    ll ans=0;
    int n;
    cin >> n;
    ll h=0;
    ll a;
    cin >> a;
    h=a;
    rep(i,n-1){
        cin >> a;
        if(h>=a){
            ans+=h-a;
        }
        else{
            h=a;
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3628
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn func(a: i64, b: i64, x: i64) -> i64 {
    return (a * x) / b - a * (x / b);
}

fn main() {
    let v = read_vec::<i64>();
    let (a, b, n) = (v[0], v[1], v[2]);
    if n >= b - 1 {
        let ans = func(a, b, b - 1);
        println!("{}", ans);
    } else {
        let ans = func(a, b, n);
        println!("{}", ans);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main(){
  std::string A, B;
  std::cin >> A >> B;
  if(A.size() > B.size()) std::cout << "GREATER" << std::endl;
  else if(A.size() < B.size()) std::cout << "LESS" << std::endl;
  else if(A.compare(B) > 0) std::cout << "GREATER" << std::endl;
  else if(A == B) std::cout << "EQUAL" << std::endl;
  else std::cout << "LESS" << std::endl;
}

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

macro_rules! parse {
    ($iter: ident) => {
        $iter.next().unwrap().parse().unwrap()
    };
    ($iter: ident,2) => {
        (parse!($iter), parse!($iter))
    };
    ($iter: ident,3) => {
        (parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident,4) => {
        (parse!($iter), parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident, $n: ident) => {
        $iter.take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let n = parse!(iter);
    let mut m: HashMap<String, usize> = HashMap::new();
    for _ in 0..n {
        let s: String = iter.next().unwrap().into();
        let v = *m.get(&s).unwrap_or(&0);
        m.insert(s, v + 1);
    }
    let mut m: Vec<_> = m.into_iter().collect();
    m.sort();
    let c: usize = m.iter().map(|x| x.1).max().unwrap();
    for (s, i) in m {
        if i == c {
            println!("{}", s);
        }
    }
}


Measured memory_bytes: 25940