akhauriyash/Code-Regression huggingface dataset:
# include <cstdio>
int N ;
int main ()
{
scanf ("%d" ,& N );
int res = N ;
for ( int i =0; i <= N ; i ++)
{
int cc =0;
int t = i ;
while (t >0) cc += t %6 , t /=6;
t=N - i ;
while (t >0) cc += t %9 , t /=9;
if ( res > cc ) res = cc ;
}
printf ("%d\n " , res );
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  string s;
  cin >> s;
  
  int a = 0;
  int b = 0;
  for(int i = 0 ; i < s.size() ; i++){
    if(s.at(i) == '1'){
      a++;
    }
    else{
      b++;
    }
  }
  cout << 2*min(a,b) << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            lstInp.Add(int.Parse(sS[0]));
            lstInp.Add(int.Parse(sS[1]));
            int iK = int.Parse(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstInp.Sort();                                                          // 小さい順に変更
            List<int> lstDiv = new List<int>();
            for (int i = 1; i <= lstInp[0]; i++)                                    // 小さい方まで回す
            {
                if (lstInp[0] % i == 0 && lstInp[1] % i == 0) { lstDiv.Add(i); }    // 公約数保持
            }
            lstDiv.Reverse();                                                       // 大きい順に変更

            // 出力
            System.Console.WriteLine("{0}", lstDiv[iK - 1].ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int H,W,h,w;
ll csum[510][510];


int main(void){
	cin >> H >> W >> h >> w;

	rep(i,1,H+1)rep(j,1,W+1){
		if(i-h >= 0 and j-w>=0){
			csum[i][j] = csum[i-h][j] + csum[i][j-w] - csum[i-h][j-w] -1LL;
		}else{
			csum[i][j]=1000000LL;
		}
	}

	/*
	rep(i,1,H+1){
		rep(j,1,W+1){
			cout << (j==1?"":" ") << csum[i][j];
		}
		cout << endl;
	}
	*/

	if(csum[H][W]>0){
		puts("Yes");
		rep(i,1,H+1){
			rep(j,1,W+1){
				ll ans = csum[i][j]-csum[i-1][j]-csum[i][j-1]+csum[i-1][j-1];
				cout << (j==1?"":" ") << ans;
			}
			cout << endl;
		}
	}
	else{
		puts("No");
	}

	return 0;
}

Measured memory_bytes: 4352
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;
struct Vertex {
  vector<int32_t> neighbours;
};

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

  int32_t N;
  cin >> N;
  bool is_okay = true;
  char last_word = 0;
  set<string> m;
  for (int32_t i = 0; i < N; ++i) {
    string w;
    cin >> w;
    if (i > 0 && w.c_str()[0] != last_word) {
      is_okay = false;
    }
    if (m.count(w) > 0) {
      is_okay = false;
    }
    m.insert(w);
    last_word = w.c_str()[w.length() - 1];
  }
  if (is_okay) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

r, g, b = MAP()
K = INT()

cnt = 0
while r >= g:
    g *= 2
    cnt += 1
while g >= b:
    b *= 2
    cnt += 1
if cnt <= K:
    Yes()
else:
    No()


Measured memory_bytes: 9540
n = int(input())
a = list(map(int, input().split()))

    
total = 1
h = 0
if 0 in a:
    print(0)
else:
    for i in a:
        total *= i
        if total > 10**18:
            break

    if total > 10**18:
        print(-1)
    else:
        print(total)

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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 //998244353
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){	if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;}	return ans;}
template <typename T> 
T Min(T a,T b){ return a<b?a:b; }
template <typename T>
T Max(T a,T b){ return a>b?a:b; }

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	string s,t;cin>>s>>t;int c=0;
	repi(i,s.size()) if(s[i]!=t[i]) c++; db(c);
	
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



Measured memory_bytes: 3768
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main()
{
	int N;
	cin >> N;
	long long  sum = 0;
	for (int i = 1; i <= N; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			sum += i;
		}
	}

	cout << sum;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
    
int main(){
    int s;
    cin>>s;
    int a = s%100;
    int b = s/100;
    if(a>=1 && a<=12){
        if(b>=1 && b<=12) cout<<"AMBIGUOUS"<<endl;
        else cout<<"YYMM"<<endl;
    }else{
        if(b>=1 && b<=12) cout<<"MMYY"<<endl;
        else cout<<"NA"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [Usize1; n-1]
    }
    let mut cnt = vec![0; n];
    for ai in a {
        cnt[ai] += 1;
    }
    for i in cnt {
        println!("{}", i);
    }
}


Measured memory_bytes: 5628
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int x, y, z;
	int s, ans;
	scanf("%d %d", &x, &y);


	printf("%d\n", x-y+1);


	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
#define put putchar
#define ll long long
#define add(x,y)(x=((y)+x)%mo)
using namespace std;
const int N=405,mo=998244353;
int n,a[N],b[N],na,nb,s;
int iv[N],vb[N],jc[N],ny[N];
int ans,f[2][N][N][2],o;
int ksm(int x,int y){
	int t=1;
	for(;y;y>>=1,x=(ll)x*x%mo)if(y&1)t=(ll)t*x%mo;
	return t;
}
int main(){
	cin>>n;
	fo(i,1,n)cin>>a[i]>>b[i],s+=a[i];
	jc[0]=1;
	fo(i,1,400)jc[i]=(ll)jc[i-1]*i%mo;
	ny[400]=ksm(jc[400],mo-2);
	fd(i,0,399)ny[i]=(ll)ny[i+1]*(i+1)%mo;
	iv[1]=1;
	fo(i,2,400)iv[i]=mo-(ll)iv[mo%i]*(mo/i)%mo;
	f[0][0][0][0]=1;
	fo(i,1,n){
		o^=1;
		fo(j,0,na)fo(k,0,nb)fo(l,0,1)f[o][j][k][l]=0;
		int v,A=(ll)a[i]*iv[s]%mo,AA=(ll)ny[b[i]-1]*ksm(A,b[i])%mo;
		vb[0]=-1;
		fo(j,1,b[i]-1)vb[j]=(ll)vb[j-1]*iv[j]%mo*A%mo;
		fo(j,0,na)fo(k,0,nb)fo(l,0,1)if(v=f[!o][j][k][l]){
			add(f[o][j+a[i]][k][l],v);
			fo(p,0,b[i]-1)add(f[o][j][k+p][l],(ll)v*vb[p]);
			if(!l)
				add(f[o][j][k+b[i]-1][1],(ll)v*AA);
		}
		na+=a[i];nb+=b[i];
	}
	int v;
	fo(j,0,na){
		int p=(ll)j*iv[s]%mo;
		fo(k,0,nb)if(v=f[o][j][k][1]){
			add(ans,(ll)v*jc[k+1]%mo*ksm(1-p,mo-1-k-2));
		}
	}
	cout<<(ans+mo)%mo;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();


    ll n, m, k;
    cin>> n>> m>> k;


    m= max (0LL , m+ min (0LL, n-k) );
    n= max (0LL, n-k);


    cout << n <<" " <<m << '\n';

    return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
    #define ll long long
    #define sz(a) int((a).size())
    #define fr(i,n) for(int i=0;i<n;i++) 
    #define rf(i,n) for(int i=1;i<=n;i++)
    #define jdb(i,v) for(__typeof(v.begin())i=v.begin(); i!=v.end();i++)
    #define present(c,a) (find(all(c),a) != c.end())
    #define spresent(c,a) (c.find(a)!=c.end())
    #define no(s,c) s.count(c)  
    #define pb push_back 
    #define eb emplace_back
    #define mp make_pair
    #define all(c) (c).begin(),(c).end()
    #define MAX INT_MAX 
    using namespace std;
    #define f first
    #define s second                                           
    int main() 
    { 
        int n;
        cin>>n;
        std::vector<int> v(n);
        fr(i,n)
        cin>>v[i];
        sort(all(v));
        int sum=0;
        fr(i,n-1)
        sum+=v[i];
        if(sum>v[n-1])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        return 0; 
    }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define N 10
#define M 10000

using namespace std;

int data[N][N];

void Init(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      if(i == j) data[i][j] = 0;
      else data[i][j] = M;
    }
  }
}

void WarshallFloyd(int& n){
  for(int k=0; k<n; ++k){
    for(int i=0; i<n; ++i){
      for(int j=0; j<n; ++j){
	data[i][j] = min(data[i][j], data[i][k] + data[k][j]);
      }
    }
  }
}

void PrintMinTime(int& n){
  int i, j, m, m_, t;
  m = N*M;
  for(i=0, m=N*M; i<n; ++i){
    for(j=0, m_=0; j<n; ++j) m_ += data[i][j];
    if(m > m_){
      t = i;
      m = m_;
    }
  }
  cout << t << " " << m << endl;
}

int main(){
  int i, n, m, a, b, c;

  while(1){
    cin >> n;
    if(n == 0) break;

    Init();
    for(i=0, m=0; i<n; ++i){
      cin >> a >> b >> c;
      data[a][b] = c;
      data[b][a] = c;
      m = max(m, a);
      m = max(m, b);
    }
    ++m;
    WarshallFloyd(m);
    PrintMinTime(m);
  }
  return 0;
}

Measured memory_bytes: 1160
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
    exit()
else:
    if a==1 or b==n:
        print((b-a)//2+1)
    else:
        print((b-a+2*min(a-1,n-b))//2+1)

Measured memory_bytes: 38256
import Data.List

main = do
 a <- getLine
 print $ analyze a

analyze :: String -> Integer
analyze str = 1 + c2 l - foo
 where 
  l = genericLength str
  foo = sum . map c2 . map genericLength . group . sort $ str

c2 :: Integer -> Integer
c2 n = n * (n-1) `div` 2

Measured memory_bytes: 22780
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<int> A(n);
    for (auto &&i : A) scanf("%d", &i);
    sort(A.begin(),A.end(), greater<>());
    int ok = -1, ng = n;
    while(ng-ok > 1){
        int mid = (ok+ng)/2;
        vector<pair<ll, ll>> val(n);
        ll S = 0;
        for (int i = 0; i < n; ++i) val[i].second = i;
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if(i == mid) continue;
            if(A[i] <= A[mid] + m){
                S += min(m, A[mid] - A[i] + m);
                val[i].first = min(m, A[mid] - A[i] + m);
            }else {
                S += m, cnt++;
                val[i].first = m;
            }

        }
        sort(val.begin(),val.end());
        for (int i = 0; i < n; ++i) {
            if(val[i].second == mid) continue;
            if(S >= (ll)(v-1)*m) continue;
            S += m - val[i].first;
            cnt++;
        }
        if(cnt < p) ok = mid;
        else ng = mid;
    }
    cout << ok+1 << "\n";
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MAX = 100100;
const int INF = 1<<29;

int top = -INF, bot = INF, le = INF, ri = -INF;

int N;
int x[MAX], y[MAX];

bool topleft(int x, int y, int w) {
    return (le <= x && x <= le+w) && (top-w <= y && y <= top+w);
}
bool topright(int x, int y, int w) {
    return (ri-w <= x && x <= ri) && (top-w <= y && y <= top+w);
}
bool botleft(int x, int y, int w) {
    return (le <= x && x <= le+w) && (bot <= y && y <= bot+w);
}
bool botright(int x, int y, int w) {
    return (ri-w <= x && x <= ri) && (bot <= y && y <= bot+w);
}

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    while (cin >> N) {
        top = -INF, bot = INF, le = INF, ri = -INF;
        for (int i = 0; i < N; ++i) {
            cin >> x[i] >> y[i];
            int nx = x[i] - y[i], ny = x[i] + y[i];
            x[i] = nx, y[i] = ny;
            chmax(top, ny); chmin(bot, ny); chmax(ri, nx); chmin(le, nx);
        }
        int lo = 0, hi = 1<<29;
        while (hi - lo > 1) {
            int mid = (lo + hi)/2;
            
            // topleft & botright
            bool ok = true;
            for (int i = 0; i < N; ++i) {
                if ( !topleft(x[i], y[i], mid) && !botright(x[i], y[i], mid) ) ok = false;
            }
            if (ok) { hi = mid; continue; }
                      
            // topright & botleft
            ok = true;
            for (int i = 0; i < N; ++i) {
                if ( !topright(x[i], y[i], mid) && !botleft(x[i], y[i], mid) ) ok = false;
            }
            if (ok) { hi = mid; continue; }
            
            lo = mid;
        }
        
        cout << hi << endl;
    }
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    if( s.size() % 2 != 0 ) {
        cout << "No" << endl;
        return 0;

    }
    for( int i = 0; i < s.size() - 1; i += 2 ) {
        if( s[i] != 'h' || s[i + 1] != 'i' ) {
            cout << "No" << endl;
            return 0;

        }
    }
    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input1 = Console.ReadLine().Split(' ');
        int H = int.Parse(input1[0]);
        int W = int.Parse(input1[1]);
        input1 = Console.ReadLine().Split(' ');
        int h = int.Parse(input1[0]);
        int w = int.Parse(input1[1]);
        Console.WriteLine((H - h) * (W - w));
    }
}

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

int main()
{
  int N;
  cin>>N;
  long long rtn=1,an,m18=1e18;
  while(N-->0){
    cin>>an;
    if(an==0){rtn=0;break;}
    else if(rtn<0){continue;}
    else if(m18/rtn<an){rtn=-1;}
    else{rtn*=an;}
  }
  cout<<rtn<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;

template <typename T>
struct SparseTable {
    int n;
    vector< vector<T> > table;
    vector<int> log_table;

    //使うときは、この2つを適宜変更する
    static T merge(T x, T y);
    static T INITIAL_VALUE;

    SparseTable(const vector<T>& v) {
        n = v.size();

        log_table.resize(n + 1, 0);
        for (int i = 2; i <= n; i++) {
            log_table[i] = log_table[i >> 1] + 1;
        }

        table.resize(log_table[n] + 1, vector<T>(n));
        for (int i = 0; i < n; i++) {
            table[0][i] = v[i];
        }

        size_t sz = table.size();
        for (int i = 1; i < sz; i++) {
            for (int j = 0; j + (1 << i) <= n; j++) {
                table[i][j] = merge(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
            }
        }
    }

    //区間[l, r)に対するクエリに答える
    T query(int l, int r) {
        if (l == r) return INITIAL_VALUE;
        int k = log_table[r - l];
        return merge(table[k][l], table[k][r - (1 << k)]);
    }
};

//使うときは以下2つを変更
//非可換の場合は順序に注意！！！
template <typename T>
inline T SparseTable<T>::merge(T x, T y) {
    return max(x, y);
}

//本来は必要無いはずだけど、区間幅0のときにバグるので一応単位元を用意
//(区間幅0のときは例外処理した方が良い？)
template <typename T>
T SparseTable<T>::INITIAL_VALUE = 0;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    SparseTable<int> st(a);
    for (int i = 0; i < n; i++) {
        cout << max(st.query(0, i), st.query(i + 1, n)) << "\n";
    }
    return 0;
}


Measured memory_bytes: 17264
/*  ex7-1
    toshiwaka */
 
//point構造体
typedef struct point{
    int x_elem;
    int y_elem;
}point;
 
//ref_pointからx,y軸方向にshift_x,shift_yだけそれぞれ移動
//移動後の点の座標をshifted_pointのメンバに代入
void shift_point(point *shifted_point, point ref_point, int shift_x, int shift_y);
 
#include <stdio.h>
 
int main(void) {
  //point:正方形の頂点
  //diff:2点間のx,y軸方向の距離
  point point[4], diff;
 
  //入力
  scanf("%d %d %d %d", &point[0].x_elem, &point[0].y_elem, &point[1].x_elem, &point[1].y_elem);
 
  //2点間のx,y軸方向の距離
  diff.x_elem = point[1].x_elem - point[0].x_elem;
  diff.y_elem = point[1].y_elem - point[0].y_elem;
 
  //残りの２点を算出
  shift_point(&point[2], point[1], -1 * diff.y_elem, diff.x_elem);
  shift_point(&point[3], point[0], -1 * diff.y_elem, diff.x_elem);
 
  //出力
  printf("%d %d %d %d\n", point[2].x_elem, point[2].y_elem, point[3].x_elem, point[3].y_elem);
 
  return 0;
}
 
 
//ref_pointからx,y軸方向にshift_x,shift_yだけそれぞれ移動
//移動後の点の座標をshifted_pointのメンバに代入
void shift_point(point *shifted_point, point ref_point, int shift_x, int shift_y){
  shifted_point->x_elem = ref_point.x_elem + shift_x;
  shifted_point->y_elem = ref_point.y_elem + shift_y;
};

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


using namespace std;

int Max = 1000000007;

int main() {


    int n;
    long long output_10 = 1;
    long long output_9 = 1;
    long long output_8 = 1;
    long long output = 0;
    cin >> n;
    if (n == 1) {
        output = 0;
    }
    else {
        for (int i = 0; i < n; i++) {
            output_10 *= 10;
            output_10 = output_10 % Max;
            output_9 *= 9;
            output_9 = output_9 % Max;
            output_8 *= 8;
            output_8 = output_8 % Max;
        }
        output = output_10 - 2 * output_9 + output_8;
        output %= Max;
    }
    
    if (output < 0) {
        output += Max;
    }
    cout << output;
    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int  n;
    cin >> n;
    if(n % 10 == 3) {
        cout << "bon" << endl;
    } else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    return 0;
}




Measured memory_bytes: 3636
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	double a,b,x,ans;cin>>a>>b>>x;
	if(x<(a*a*b)/2) ans = atan((a*b*b)/(2*x));
	else ans = atan((2*(b*a*a-x))/(a*a*a));
	ans = (ans*180)/M_PI;
	cout<<setprecision(15)<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    string s;
    cin >> s;
    if (s == "RRR")
        cout << 3 << endl;
    else if (s == "RRS" || s == "SRR")
        cout << 2 << endl;
    else if (s == "SSS")
        cout << 0 << endl;
    else
        cout << 1 << endl;
}

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

const int INF = 1e9+7;

int main() {
	string s;
	cin >> s;
	int a;
	int z;
	for(int i=0; i<s.size(); i++){
		if(s.at(i) == 'A'){
			a = i;
			break;
		}
	}
	for(int i=s.size()-1; i>=0; i--){
		if(s.at(i) == 'Z'){
			z = i;
			break;
		}
	}
	cout << z-a+1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
const int maxn = 1e5 + 3;
ll x[maxn], y[maxn];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i<n; ++i)
	scanf("%lld", &x[i]);
	for (int i = 0; i<m; ++i)
	scanf("%lld", &y[i]);
	ll W = 0, H = 0;
	for (int i = 0, j = n - 1; i < j; ++i, --j)
		W = (W + (x[j] - x[i])*(j - i) % mod) % mod;
	for (int i = 0, j = m - 1; i < j; ++i, --j)
		H = (H + (y[j] - y[i])*(j - i) % mod) % mod;
	
	printf("%lld\n", (W*H) % mod);

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll n;
ll prime[10100];
bool is_prime[10100];

ll cnt[1010];

void solve(ll num){
	int buf = num;
	for (ll i = 0; buf != 1;){
		//cout << prime[i] << " " << i << " " << buf << endl;
		if (buf%prime[i] == 0){
			buf /= prime[i];
			cnt[prime[i]]++;
		}
		else{
			i++;
		}
	}
}

int main(){
	ll p = 0;
	fill(is_prime, is_prime + 10100, 1);
	is_prime[0] = 0;
	is_prime[1] = 0;
	for (ll i = 2; i <= 1000; i++){
		if (is_prime[i]){
			prime[p++] = i;
			for (ll j = i * 2; j <= 1000; j += i){
				is_prime[j] = 0;
			}
		}
	}

	cin >> n;
	FOR(i, 2, n + 1){
		solve(i);
		//cout << "!" << endl;
	}
	ll ans = 1;
	for (ll i = 0; i<=1000;i++){
		ans *= (cnt[i] + 1);
		ans %= INF;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//
////clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//
////debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


bool isP(int n){
   if(n==1)  return false;
   if(n==2)  return true;
   if(n%2==0)return false;
   for(auto i=3;i<=sqrt(n);i+=2)
      if(n%i==0)return false;
   return true;
}

int main(){
 int n,t,count=0;
 cin>>n;
 REP(i,n){
// for(int i=0;i<100;i++){
    cin>>t;
    if(isP(t)){
	//cout<<t<<" j"<<endl;
	count++;
    }
 }
 cout<<count<<endl; 
 return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int N, M;
vector<vector<int>> G;

vector<double> calc() {
  vector<double> dp(N);
  for(int i = N - 1; i --> 0; ) {
    double sum = 0;
    double cnt = 0;
    for(auto j: G[i]) {
      sum += dp[j];
      cnt += 1;
    }
    dp[i] = sum / cnt + 1;
    if(cnt == 0) {
      return vector<double>();
    }
  }
  return dp;
}

int main() {
  cin >> N >> M;
  G.resize(N);
  rep(i,0,M) {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
  }
  auto dp = calc();
  double ans = dp[0];
  rep(v,0,N - 1) {
    int ei = 0;
    auto& g = G[v];
    for(int i = 0;i < G[v].size(); i++) {
      if(dp[g[ei]] < dp[g[i]]) {
        ei = i;
      }
    }
    int t = g[ei];
    g.erase(std::begin(g) + ei);
    auto vdp = calc();
    g.push_back(t);
    if(vdp.size() > 0) {
      ans = std::min(ans, vdp[0]);
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
}




Measured memory_bytes: 1408
S = input()
p1 = 0
p2 = 1

d1 = 0
d2 = 0
for s in S:
    s = int(s)
    if p1 != s:
        d1 += 1
    if p2 != s:
        d2 += 1
    p1 ^= 1
    p2 ^= 1

print(min(d1, d2))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
int nx[4]={0,-1,0,1};
int ny[4]={-1,0,1,0};

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    int h,w;
    bool flag=true;
    cin >> h >>w;
    vector<vector<char>>s(h,vector<char>(w));
    rep(i,h) rep(j,w)  cin >> s[i][j];
    rep(i,h){
        //if(flag==false) break;
        rep(j,w){
            if(s[i][j]=='#'){
                int count=0;
                rep(k,4){
                    int x=j+nx[k];int y=i+ny[k];
                    if(x<0||x>=w||y<0||y>=h) continue;
                    if(s[y][x]=='#')count++;
                }
                if(count==0) flag=false;
            }
        }
    }
    if(flag) cout << "Yes" <<endl;
    else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string A,B,C;
  cin >>A>>B>>C;
  
  if ((A.at(A.length()-1)==B.at(0))&&(B.at(B.length()-1)==C.at(0))){
    cout <<"YES"<<endl;
    return 0;
  }
  cout<<"NO"<<endl;
    
    
  return 0;
}

           

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define Cout(s) cout<<s<<endl
typedef long long ll;
using namespace std;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;

bool hantei(vector<vector<char>> x, int i, int j)
{
	if (x[i][j] == '#')
		if (x[i + 1][j] == '#' || x[i - 1][j] == '#' || x[i][j + 1] == '#' || x[i][j - 1] == '#')
			return true;
		else
			return false;
	else
		return true;
}

int main()
{
	int h, w; cin >> h >> w;
	vector<vector<char>> x(w + 2, vector<char>(h + 2));
	rep(i,w)
	{
		rep(j, h)
			cin >> x[i+1][j+1];
	}
	bool t = true;
	rep(i,w)
	{rep(j,h)
	{if(!(hantei(x,i+1,j+1)))
		t=false;
	} }
	Cout(Yes(t));
	return 0;
}

Measured memory_bytes: 256
#define FRER() freopen("i.txt","r",stdin)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,inf=0x3f3f3f3f;
struct TWO_SAT {
    int n,hd[N],ne,mk[N],sta[N],tp;
    struct E {int v,nxt;} e[N*80];
    void link(int u,int v) {e[ne]= {v,hd[u]},hd[u]=ne++;}
    void link(int u,int v,int f1,int f2) {
        link(u<<1|f1,v<<1|f2);
        link(v<<1|(!f2),u<<1|(!f1));
    }
    void init(int _n) {
        n=_n,ne=tp=0;
        for(int i=0; i<=(n<<1|1); ++i)mk[i]=0,hd[i]=-1;
    }
    bool dfs(int u) {
        if(mk[u^1])return 0;
        if(mk[u])return 1;
        mk[u]=1,sta[tp++]=u;
        for(int i=hd[u]; ~i; i=e[i].nxt)if(!dfs(e[i].v))return 0;
        return 1;
    }
    bool check() {
        for(int i=1; i<=n; ++i)mk[i]=0;
        for(int i=1; i<=n; ++i)if(!mk[i<<1]&&!mk[i<<1|1]) {
                tp=0;
                if(!dfs(i<<1)) {
                    for(; tp; mk[sta[--tp]]=0);
                    if(!dfs(i<<1|1))return 0;
                }
            }
        return 1;
    }
} twosat;
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((l+r)>>1)
int n,tot,X[N],Y[N],nb,nd[N];
struct D {
    int x,i,f;
    bool operator<(const D& b)const {return x<b.x;}
} b[N];
void build(int u=1,int l=0,int r=nb-1) {
    if(l==r) {nd[l]=u; return;}
    build(ls,l,mid),build(rs,mid+1,r);
}
void build2(int u=1,int l=0,int r=nb-1) {
    if(l==r)return;
    build2(ls,l,mid),build2(rs,mid+1,r);
    twosat.link(u,ls,0,0),twosat.link(u,rs,0,0);
}
void upd(int v,int L,int R,int u=1,int l=0,int r=nb-1) {
    if(l>=L&&r<=R) {twosat.link(v,u,1,0); return;}
    if(l>R||r<L)return;
    upd(v,L,R,ls,l,mid),upd(v,L,R,rs,mid+1,r);
}
int lb(int x) {return lower_bound(b,b+nb, (D) {x,0,0})-b;}
int rb(int x) {return upper_bound(b,b+nb, (D) {x,0,0})-b-1;}
bool ok(int d) {
    twosat.init((n+10)<<3);
    build2();
    for(int i=1; i<=n; ++i) {
        upd(nd[X[i]],lb(b[X[i]].x-d+1),X[i]-1);
        upd(nd[X[i]],X[i]+1,rb(b[X[i]].x+d-1));
        upd(nd[Y[i]],lb(b[Y[i]].x-d+1),Y[i]-1);
        upd(nd[Y[i]],Y[i]+1,rb(b[Y[i]].x+d-1));
        twosat.link(nd[X[i]],nd[Y[i]],1,0);
        twosat.link(nd[X[i]],nd[Y[i]],0,1);
    }
    return twosat.check();
}
int bi(int l,int r) {
    int ret=l;
    while(l<=r) {
        if(ok(mid))ret=mid,l=mid+1;
        else r=mid-1;
    }
    return ret;
}
int main() {
    //FRER();
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)scanf("%d%d",&X[i],&Y[i]);
    b[nb++]= {~inf,-1,-1},b[nb++]= {inf,-1,-1};
    for(int i=1; i<=n; ++i)b[nb++]= {X[i],i,0},b[nb++]= {Y[i],i,1};
    sort(b,b+nb);
    for(int i=1; i<nb-1; ++i) {
        if(b[i].f==0)X[b[i].i]=i;
        else Y[b[i].i]=i;
    }
    build();
    printf("%d\n",bi(0,inf));
    return 0;
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  REP(i, M) cin >> A[i];
  vector<int> num = {0,2,5,5,4,5,6,3,7,6};
  vector<string> dp(N+1, "x");
  dp[0] = "";
  FOR(i, 1, N+1) {
    REP(j, M) {
      if(i-num[A[j]] >= 0) {
        if(dp[i-num[A[j]]] == "x") continue;
        if(dp[i] == "x" || dp[i-num[A[j]]].size() >= dp[i].size()) {
          dp[i] = dp[i-num[A[j]]] + (char)(A[j] + '0');
        } else if(dp[i-num[A[j]]].size() + 1 == dp[i].size()) {
          dp[i] = max(dp[i], dp[i-num[A[j]]] + (char)(A[j] + '0'));
        }
      }
    }
    //cout << dp[i] << endl;
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 41088
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

long long calc(long long x,long long y){
	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}

int main(){

	char buf[101];
	int n_count,w_count,length;
	long long int bunshi,bunbo,common;

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		for(length = 0;buf[length] != '\0';length++);

		n_count = w_count = 0;

		for(int i = length-1;i>= 0; i--){
			if(buf[i] == 'n'){
				if(n_count == 0){
					if(w_count == 0){
						//Do nothing
					}else{
						bunshi = 90*pow(2,w_count) - 90;
						bunbo = pow(2,w_count);
					}
				}else{
					if(w_count == 0){
						//Do nothing
					}else{
						bunshi = 2*bunshi - 90;
						bunbo *= 2;
					}
				}
				n_count++;
			}
			else if(buf[i] == 'w'){
				if(w_count == 0){
					if(n_count == 0){
						//Do nothing
					}else{
						bunshi = 90;
						bunbo = pow(2,n_count);
					}
				}else{
					if(n_count == 0){
						//Do nothing
					}else{
						bunshi = 2*bunshi + 90;
						bunbo *= 2;
					}
				}
				w_count++;
			}
		}

		if(n_count == 0){
			printf("90\n");
			continue;
		}else if(w_count == 0){
			printf("0\n");
			continue;
		}else{
			if(bunbo > bunshi){
				common = calc(bunbo,bunshi);
			}else{
				common = calc(bunshi,bunbo);
			}

			if(bunbo/common == 1){
				printf("%lld\n",bunshi/common);
			}else{
				printf("%lld/%lld\n",bunshi/common,bunbo/common);
			}

		}
	}

    return 0;
}

Measured memory_bytes: 2632
#include <cstdio>

typedef long long LL;

int p[100010];
bool np[1000010];
int cntp;

void SievePrime(int n) {
  LL t;
  for(int i = 2; i <= n; ++i) {
    if(!np[i]) p[cntp++] = i;
    for(int j = 0; j < cntp && (t = 1ll * i * p[j]) <= n; ++j) {
      np[t] = true;
      if(i % p[j] == 0) break;
    }
  }
}

int main() {
  SievePrime(1000000);
  int n;
  while(scanf("%d", &n) != EOF) {
    int ans = 0;
    for(int i = 2; i <= n; ++i) {
      if(!np[i]) ++ans;
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

typedef long long Int;

using namespace std;

int main()
{
  int N;
  int a[300000];
  Int L[100001], R[100001];
  scanf("%d", &N);
  
  for (int i = 0; i < 3 * N; i++) {
    scanf("%d", &a[i]);
  }
  
  Int tot = 0;
  Int tot2 = 0;
  priority_queue<Int, vector<Int>, greater<Int>> pq;
  for (int i = 0; i < 2 * N; i++) {
    tot += a[i];
    pq.push(a[i]);
    if (pq.size() > N) {
      tot2 += pq.top(); pq.pop();
    }
    if (pq.size() == N) L[i - N + 1] = tot - tot2;
  }
  
  tot = 0;
  tot2 = 0;
  priority_queue<Int> pq2;
  for (int i = 3 * N - 1; i >= N; i--) {
    tot += a[i];
    pq2.push(a[i]);
    if (pq2.size() > N) {
      tot2 += pq2.top(); pq2.pop();
    }
    if (pq2.size() == N) R[2 * N - i] = tot - tot2;
  }
  
  Int ans = L[0] - R[N];
  for (int i = 1; i <= N; i++) {
    ans = max(ans, L[i] - R[N - i]);
  }
  
  printf("%lld\n", ans);
  
  return 0;
}

Measured memory_bytes: 5236
N,K,*L=map(int,open(0).read().split())
S=sorted([(d,t)for t,d in zip(*[iter(L)]*2)],reverse=True)
In=set()
X=0
uni=[]
dub=[]
for d,t in S:
	if t not in In:
		In.add(t)
		uni.append(d)
		X+=1
		if X==K:
			break
	else:
		dub.append(d)
det=sum(dub[:K-X])
dub=dub[K-X:]
for d in dub:
	if uni[-1]+2*X-1<=d:
		uni.pop()
		X-=1
		det+=d
	else:
		break
print(sum(uni)+det+X**2)



Measured memory_bytes: 25868
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)
#define Fj(n) for(int j=0;j<n;++j)
const int MOD=1e9+7;

int main()
{
    long x,y;
    cin >> x >> y;
    long sum=0;
    if(x==1) sum += 3e5;
    else if(x==2) sum += 2e5;
    else if(x==3) sum += 1e5;
    if(y==1) sum += 3e5;
    else if(y==2) sum += 2e5;
    else if(y==3) sum += 1e5;
    if(x==1 && y==1) sum += 4e5;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000
#define MAX_ 50000
 
void merge_sort(int x[],int left,int right){
    int mid,i,j;
    int temp[MAX];
     
    if(left >= right)
        return;
     
    mid = (left + right) / 2;
    merge_sort(x, left ,mid);
    merge_sort(x, mid + 1,right);
     
    for(int i = left;i <= mid; i++){
        temp[i] = x[i];
    }
     
    for(int i = mid + 1,j = right; i <= right; i++,j--){
        temp[i] = x[j];
    }
     
    i = left;
    j = right;
     
    for(int k = left; k <= right; k++){
        if(temp[i] <= temp[j]) x[k] = temp[i++];
        else x[k] = temp[j--];
    }
}
 
 
int main(){
    int n,S[MAX],q,T[MAX_],cnt=0;
     
    cin >> n;
    for(int i = 0;i < n; i++) cin >> S[i];
     
    cin >> q;
    for(int j = 0;j < q; j++) cin >> T[j];
     
    merge_sort(S, 0, n-1);
    merge_sort(T, 0, q-1);
     
     
    for(int i = 0,j = 0;i < n && j < q ; ){
        if(S[i]==T[j]) cnt++,i++,j++;
        else if(S[i] < T[j]) i++;
        else if(S[i] > T[j]) j++;
         
    }
     
    cout << cnt << endl;
     
    return 0;
}



Measured memory_bytes: 10236
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout << xs[i] << " ";
	cout << xs[xs.size()-1] << endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	for(int i=0; i<N; i++) cin >> A[i];
	vector<ll> cum1(N), cum2(N);
	cum1[0] = max(1LL, A[0]);
	cum2[0] = min(-1LL, A[0]);
	for(int i=1; i<N; i++){
		if(i%2){
			cum1[i] = min(-1LL, cum1[i-1]+A[i]);
			cum2[i] = max(1LL, cum2[i-1]+A[i]);
		} else {
			cum1[i] = max(1LL, cum1[i-1]+A[i]);
			cum2[i] = min(-1LL, cum2[i-1]+A[i]);
		}
	}

	ll a1=abs(cum1[0]-A[0]), a2=abs(cum2[0]-A[0]);
	for(int i=1; i<N; i++){
		a1 += abs(cum1[i]-cum1[i-1]-A[i]);
		a2 += abs(cum2[i]-cum2[i-1]-A[i]);
	}
	cout << min(a1, a2) << endl;
	return 0;
}


Measured memory_bytes: 2560
x = int(input())

if 400 <= x <= 599 :
    print(8)
elif 600 <= x <= 799 :
    print(7)
elif 800 <= x <= 999 :
    print(6)
elif 1000 <= x <= 1199 :
    print(5)
elif 1200 <= x <= 1399 :
    print(4)
elif 1400 <= x <= 1599 :
    print(3)
elif 1600 <= x <= 1799 :
    print(2)
elif 1800 <= x <= 1999 :
    print(1)


Measured memory_bytes: 9180
A,B,C = [input() for i in range(3)]
a = [A[:1], A[1:2], A[2:]]
b = [B[:1], B[1:2], B[2:]]
c = [C[:1], C[1:2], C[2:]]
print(a.pop(0) + b.pop(1) + c.pop(2))

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

int main() {
  string s;
  cin >> s;
  int ans = 0, temp = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') temp++;
    else temp = 0;
    ans = max(temp, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
input = STDIN.gets.chomp.split("")

len = input.count
cnt = Hash.new(0)

input.each { |e| cnt[e]+=1 }

# p len
ans = (len/2).to_i

if cnt.values().all? { |e| e==1 }
else
  cnt.each{|key,val|
    if val>1
      # p key
      pos_list = []
      input.each_with_index { |e, i|  
        pos_list.push i if e == key
      }
      # p pos_list
      cand_list = [pos_list.first,len-pos_list.last-1]
      (pos_list.length()-1).times { |n|
        cand_list.push( ((pos_list[n+1]-pos_list[n]-1)/1).to_i )
      }
      # p cand_list
      _ans = cand_list.max
      ans = _ans if _ans < ans
    end
  }
end

print ans

Measured memory_bytes: 3836
#include <iostream>
#include <string.h>
using namespace std;
int n,s;
int tmp[11];
int cnt;
void rec(int m)
{
	for(int i=tmp[m-1]+1;i<=9;i++)
	{
		tmp[m]=i;
		if(m<n) rec(m+1);
		if(m!=n) continue;
		int sum=0;
		for(int j=1;j<=n;j++) sum+=tmp[j];
		if(sum==s) cnt++;
	}
}
int main()
{
	while(1)
	{
		cin >> n >> s ; if(!n && !s) break;
		memset(tmp,0,sizeof(tmp));
		tmp[0]=-1; cnt=0;
		rec(1);
		cout << cnt << '\n' ;
	}
}

Measured memory_bytes: 1160