akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
const int MOD = 1000000007;
const int MAX = 1000010;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int 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;
  }
}

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

map<ll, ll> prime_decomposition(ll n){
  map<ll, ll> mp;
  for(ll p = 2; p*p <=n; p++){
    if(n%p!=0) continue;
    ll cnt = 0;
    while(n%p == 0){cnt++; n /= p;}
    mp[p] = cnt;
  }
  if(n!=1) mp[n] = 1;
  return mp;
}

int main() {
  ll n,m; cin >> n >> m;
  auto mp = prime_decomposition(m);
  COMinit();
  ll ans = 1;
  FOREACH(x,mp){
    ll e = x.second;
    (ans *= COM(e+n-1, e)) %= MOD; 
  }
  cout << ans << endl;
}

Measured memory_bytes: 23680
H, W = map(int, input().split())
A = [input() for _ in range(H)]
A = [aa for aa in A if any(a=="#" for a in aa)]
A = list(map(list, zip(*A)))
A = [aa for aa in A if any(a=="#" for a in aa)]
A = list(map(list, zip(*A)))
for aa in A:
    print("".join(aa))

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define PB push_back
#define db long double
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=3e5+10,mod=998244353;
char str[N];
int n;
int a[3][N],cnt[3],len[3];
int main() {
	rd(n);
	scanf("%s",str+1);
	for(int i=1;i<=3*n;++i) {
		int c=str[i]=='R'?0:(str[i]=='G'?1:2);
		cnt[c]++;
		int pos=-1;
		for(int j=0;j<3;++j) if(cnt[j]>=cnt[c]) pos++;
//		cout<<pos<<endl;
		a[pos][++len[pos]]=i;
	}
//	for(int j=0;j<3;++j) {
//		printf("%d:",j);
//		for(int i=1;i<=n;++i) printf("%d ",a[j][i]);
//		puts("");
//	}
	int ans=1;
	int p0=1;
	for(int i=1;i<=n;++i) {
		while(p0<n&&a[0][p0+1]<a[1][i]) p0++;
//		cout<<i<<':'<<p0<<endl;
		ans=ans*(ll)(p0-(i-1))%mod;
	}
	int p2=n;
	for(int i=n;i>=1;--i) {
		while(p2>1&&a[2][p2-1]>a[1][i]) p2--;
//		cout<<i<<':'<<p2<<endl;
		ans=ans*(ll)(n-p2+1-(n-i))%mod;
	}
	for(int i=1;i<=n;++i) ans=ans*(ll)i%mod;
	printf("%d",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

#define EPS 1e-14
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define INFLL (ll)1e18 //Long long infinity
#define INF (int)1e9 //Int infinity
#define MX 100005

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<string> vstr;

#define us unordered_set
#define um unordered_map
#define bs bitset

#define RANGE(i,a,b,d) for (int i=min((int)a,(int)b); i<max((int)a,(int)b); i+=d)
#define RRANGE(i,a,b,d) for (int i=max((int)a,(int)b); i>min((int)a,(int)b); i+=d)
#define FOR(i,a,b) RANGE(i,a,b,1)
#define RFOR(i,a,b) RRANGE(i,a,b,-1)
#define REP(i,s) FOR(i,0,s)
#define RREP(i,s) RFOR(i,s-1,-1)
#define FORIT(it,l) for (auto it = l.begin(); it != l.end(); it++)
#define EACH(x,v) for (auto &x : v)

#define sz(x) (int)(x).size()
#define len(x) (int)sizeof(x)/sizeof(*x)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define contains(m,x) (m.find(x) != m.end()) // check if an element in a map
#define isIn(S, s) (S.find(s) != string::npos) // check if substring

#define pv(v) EACH(x, v) cout << x << " "; cout << endl; // print vector/array
#define pvv(vv) EACH(xx, vv){pv(xx);} // print 2-d vector/2-d array
#define pm(m) EACH(x, m) cout << x.F << ":" << x.S << " "; cout << endl; //print map/lookup table

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace std{
  // Used for hashing pair
  template <> struct hash<pi>{
    size_t operator()(const pi&x)const{
      ll P=38923, Q=109797901;
      return (size_t)((x.F*P+x.S)%Q);
    }
  };
};

// This is min queue
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
void print(T t){
  cout << t << endl;
}

//Python style printing
template<typename T, typename... Args>
void print(T t, Args... args){
  cout << t << " ";
  print(args...);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vpi tasks;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    tasks.pb({b, a});
  }
  set<int> days;
  REP(i, m) days.insert(i+1);
  sort(all(tasks), greater<pi>());
  ll sol = 0;
  EACH(task, tasks) {
    //pv(days);
    //print(task.F, task.S);
    auto day = days.lower_bound(task.S);
    if(day == days.end()) continue;
    else {
      days.erase(day);
      sol += task.F;
    }
  }
  print(sol);
  return 0;
}


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

int main(){

  int n;
  int count;

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

    count=0;

    while(n!=1){
      if(n%2==0)
	n/=2;
      else
	n=n*3+1;
      
      count ++;
    }
    
    cout << count << endl;
  }


  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int field[51][51];
int dp[51][51];

int main () {
	int w, h;
	while(cin >> h >> w) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				char c;
				cin >> c;
				field[j][i] = c - '0';
				dp[j][i] = 0x7fffffff;
			}
		}
		dp[0][0] = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				dp[j+1][i] = min(dp[j+1][i], dp[j][i] + field[j+1][i]);
				dp[j][i+1] = min(dp[j][i+1], dp[j][i] + field[j][i+1]);
			}
		}
		cout << dp[w-1][h-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
N = int(input())
P = [int(a) - 1 for a in input().split()]

ans = 0
i = 0
while i < N:
    if P[i] == i:
        ans += 1
        if i+1<N and P[i+1] == i+1:
            i += 2
        else:
            i += 1
    
    else:
        i += 1

print(ans)

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

class Edge{
public:
    int from, to;
    long long cost;
    Edge(): from(0), to(0), cost(0){};
    Edge(int u, int v, long long w): from(u), to(v), cost(w){};
    ~Edge(){};
};

void Warshall_Floyd(std::vector<Edge> &edge, int V,
    std::vector<std::vector<long long> > &d)
{
    int E = edge.size();
    const long long infty = 1e+16;
    d.clear(); d.resize(V);
    for(int i=0; i<V; i++){
        for(int j=0; j<V; j++) d[i].push_back(infty);
    }
    // initialize
    for(int i=0; i<E; i++){
        d[edge[i].from][edge[i].to] = edge[i].cost;
    }
    for(int i=0; i<V; i++) d[i][i] = 0;

    // dp
    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++) d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
        }
    }

    // print
    // for(int i=0; i<V; i++){
    //     for(int j=0; j<V; j++){
    //         if(d[i][j] < infty/10) printf("%lld ", d[i][j]);
    //         else printf("infty ");
    //     }
    //     printf("\n");
    // }
}

void to_undirected(std::vector<Edge> &edge)
{
    int M = edge.size();
    for(int i=0; i<M; i++){
        edge.push_back(Edge(edge[i].to, edge[i].from, edge[i].cost));
    }
}

void search_part(int depth, std::vector<std::vector<long long> > &distance,
    std::vector<int> &r,
    int tmp, int sum, int &min, std::vector<bool> &visited)
{
    // printf("depth = %d, tmp = %d, sum = %d\n", depth, tmp, sum);
    int R = r.size();
    if(depth == R){
        if(sum < min) min = sum;
        return;
    }

    for(int i=0; i<R; i++){
        if(visited[i] == false){
            visited[i] = true;
            int next = r[i];
            search_part(depth+1, distance, r, next, sum+distance[tmp][next], min, visited);
            visited[i] = false;
        }
    }
}

int search(std::vector<std::vector<long long> > &distance, std::vector<int> &r)
{
    int R = r.size();
    std::vector<bool> visited(R, false);
    int min = 1e+9;

    for(int i=0; i<R; i++){
        visited[i] = true;
        search_part(1, distance, r, r[i], 0, min, visited);
        visited[i] = false;
    }

    return min;
}

int main()
{
    int N, M, R;
    std::cin >> N >> M >> R;
    std::vector<int> r(R);
    for(int i=0; i<R; i++){
        scanf(" %d", &r[i]); r[i]--;
    }
    std::vector<Edge> edge(M);
    for(int i=0; i<M; i++){
        scanf(" %d %d %lld", &(edge[i].from), &(edge[i].to), &(edge[i].cost));
        edge[i].from--; edge[i].to--;
    }
    
    to_undirected(edge);
    std::vector<std::vector<long long> > distance;
    Warshall_Floyd(edge, N, distance);

    int min = search(distance, r);
    std::cout << min << std::endl;
}

Measured memory_bytes: 1224
#include <iostream>

using namespace std;

int main () {
    string S;
    cin >> S;
	string result;
  	if (S == "Sunny") result = "Cloudy";
	else if (S == "Cloudy") result = "Rainy";
  	else if (S == "Rainy") result = "Sunny";
  	
  	cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
	int n;
	cin >> n;
	rep(i, n) {
		vector<int> num(9);
		vector<string> mark(9);
		rep(j, 9) {
			cin >> num[j];
		}
		rep(j, 9) {
			cin >> mark[j];
		}
		vector<int> per(9);
		rep(j,9) per[j] = j;
		bool found = false;
		while( next_permutation(per.begin(), per.end()) ) {
			bool fail = false;
			rep(j,3) {
				rep(k,3) {
					if( mark[per[j*3]] != mark[per[j*3+k]] ) fail = true;
				}
				if( !(num[per[j*3]] == num[per[j*3+1]] && num[per[j*3]] == num[per[j*3+2]]) &&
					!(num[per[j*3]]+1 == num[per[j*3+1]] && num[per[j*3]]+2 == num[per[j*3+2]]) ) {
					fail = true;
				}

			}
			if(!fail) {
				cout << "1" << endl;
				found = true;
				break;
			}
		}
		if(!found) {
			cout << "0" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>

using namespace std;
const int maxn = 101;
int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int last = 0;
    int x;
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> x;
        if (last == x)
        {
            ++ans;
            last = 0;
        }
        else
            last = x;
    }
    cout << ans << endl;
    return 0;
}

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

mp = {0:1}
for i in range(N-1):
    A[i+1]+=A[i]
for a in A:
    if a in mp:
        mp[a]+=1
    else:
        mp[a]=1
res = 0
for v in mp.values():
    res += v*(v-1)//2
print(res)


Measured memory_bytes: 37260
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

void solve();
bool dfs(int y, int x);

int n, m;
string a[51];
string b[51];

int main() {
  cin >> n >> m;
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  solve();

  return 0;
}

void solve() {

  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) {
      if(dfs(i, j)) {
        cout << "Yes" << endl;
        return;
      }
    }
  }

  cout << "No" << endl;
}

bool dfs(int y, int x) {

  for(int i=0; i<m; ++i) {
    if(!(y+i<n)) return false;
    for(int j=0; j<m; ++j) {
      if(!(x+j<n)) return false;
      if(a[y+i][x+j]!=b[i][j]) return false;
    }
  }

  return true;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    int i=0;
    bool ok = false;
    for(i=0;i<s.size();i++){
        if(s[i]!='1') break;
        ok = true;
    }
    if(ok){
        if((ll)i>=k){
            cout << 1 << endl;
        }else{
            cout << s[i] << endl;
        }
    }else{
        cout << s[0] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
using namespace std;

int main(int argc, const char * argv[]) {
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) <<endl;
    
    /*if(b>0 && d>0){
        if(a<0 && c<0){
            if(a*c<=b*d) cout << b*d <<endl;
            else cout << a*c << endl;
        }
        else cout << b*d <<endl;
    }
    else if(b<=0 || d<=0)
    
    */
    
    return 0;
}




Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
	int n,x,t;
	cin >> n >> x >> t;
	int suma = n/x;
	if(n%x != 0){
		suma+=1;
	}
	if(n == x){
		cout << t << endl;
	}else{
		cout << suma*t << endl;
	}
	return 0;	
}	


Measured memory_bytes: 3624
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
trace _ = id

data Plane = Plane {p_rx::Int, p_ry::Int, p_z0::Int}
           deriving (Eq, Ord, Show)

solve :: Int -> Int -> [[Int]] ->
         Maybe (Int, Int, [(Int, Int, String)], Int, Int)
solve a b d | possible = Just build
            | otherwise = Nothing
  where
    vd = VU.fromListN (a*b) (concat d)
    enc x y = (x-1) * b + (y-1)
    valyx x y | trace ("valyx" ++ show (x,y)) False = undefined
    valyx x y | x <= 0 || y <= 0 = 0
              | otherwise      = vd VU.! (enc x y)
    tri' = [ptPlane x y | x <- [1..a], y <- [1..b]]
    ptPlane x y = [Plane rx ry z0
                  | rx <- cands_rx, ry <- cands_ry,
                    let z0 = calc_z rx ry, checkConvex rx ry z0]
      where
      calc_z rx ry = valyx x y - rx*x - ry*y
      cands_rx
        | x == a    = [0]
        | otherwise = [valyx (x+1) y - valyx x y .. valyx x y - valyx (x-1) y]
      cands_ry
        | y == b    = [0]
        | otherwise = [valyx x (y+1) - valyx x y .. valyx x y - valyx x (y-1)]
    xyPair = [(x,y) | x <- [1..a], y <- [1..b]]
    checkConvex rx ry z0
      = all (\(x,y) -> rx*x + ry*y + z0 >= valyx x y) xyPair

    possible = all (not . null) tri'

    tri = trace ("tri " ++ show tri0) tri0
    tri0 = nub $ map head tri'

    yMax = maximum $ map p_ry tri
    safeMax [] = 0
    safeMax xs = maximum xs
    lxMax = [safeMax $ map p_rx $ filter ((== ry) . p_ry) tri
            | ry <- [0..yMax]]
    board = [(u+1,v+1,c) | (u,v,c) <- boardM]
    boardM = [connY y | y <- [0..yMax-1]]
             ++ [connX y x | y <- [0..yMax], x <- [0 .. (lxMax !! y) - 1]]
             ++ [connP p | p <- tri]
    connY y = (bEncY y, bEncY (y+1), "Y")
    connX y x = (bEncX y x, bEncX y (x+1), "X")
    connP (Plane rx ry z0) = (bEncX ry rx, bEncT, show z0)
    bEncY y = y
    bEncX y 0 = bEncY y
    bEncX y x = (yMax+1) + (accXMax !! y) + (x-1)
    bEncT = (yMax+1) + (accXMax !! (yMax+1)) 
    accXMax = scanl' (+) 0 lxMax
    build = (bEncT + 1, length board, board, 1, bEncT + 1)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Maybe (Int, Int, [(Int, Int, String)], Int, Int)
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_a,bs_b]:remLines1 = remLines0
      a = readBInt bs_a
      b = readBInt bs_b
      d = map (map readBInt) remLines1
  in solve a b d

outAnswer :: Maybe (Int, Int, [(Int, Int, String)], Int, Int) -> IO ()
outAnswer Nothing               = putStrLn "Impossible"
outAnswer (Just (n,m,uvcs,s,t)) = do
  putStrLn "Possible"
  putStrLn $ unwords $ map show [n,m]
  putStr $ unlines $ map (\(u,v,s) -> unwords [show u, show v, s]) uvcs
  putStrLn $ unwords $ map show [s,t]

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  ll ans;
  cin >> ans;
  rep(i,n-1) {
    ll t;
    cin >> t;
    ans = gcd(ans, t);
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N, M = 0;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
}
for (int i = 0; i < N; i++) {
  M += vec.at(i);
}
M -=N;
cout << M << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
int main()
{
	fast;
	string s; cin>>s;
	int l = s.size();
	int i;
	for(i=0; i<6; i++)
	{
		if(s[2]==s[3] && s[4]==s[5])
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}



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

const int INF = 1 << 30;

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

    int dp[100100];
    for (int i = 0; i < 100100; i++) dp[i] = INF;
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        int power = 1;
        while (i + power <= N) {
            dp[i + power] = min(dp[i + power], dp[i] + 1);
            power *= 6;
        }
        power = 9;
        while (i + power <= N) {
            dp[i + power] = min(dp[i + power], dp[i] + 1);
            power *= 9;
        }
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <cstdio>
#include <string>
#include <fstream>
#include <queue>
#include <cmath>
using namespace std;
//ABC082.c

int main(void) {
	int N,t;
	cin >>N;
	vector<int>b(N+1,0);
	int change = 0;

	for (int i = 1; i < N+1; i++) {
		cin >> t;
		if (t > N)change++;
		else b[t]++;
	}
	for (int i = 1; i < N+1; i++) {
		if (b[i] != i &&b[i]!=0) {
			if(b[i]>i)
			change +=abs( b[i] - i);
			else change += b[i];
		}
	}
	printf("%d", change);
	return 0;
}

Measured memory_bytes: 640
package main

import (
    "bufio"
    "fmt"
    "os"
  	"strconv"
  	"strings"
  	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main() {
    s := nextLine()
  	ss := strings.Split(s, " ")
  	N, _ := strconv.Atoi(ss[0])//個数
  
    dic := [] string{}
    for i := 1; i <= N; i++ {    
      dic = append(dic,nextLine())
     //fmt.Println(dic)//追加
    }
   sort.Strings(dic)//並べ替え
  dics := strings.Join(dic,"")
   fmt.Println(dics)
  
}

Measured memory_bytes: 640
X = str(input())
N = int(X.split(' ')[0])
M = int(X.split(' ')[1])



if N % 2 ==1:

    for i in range(M):
        S = i+1
        T = N-i
        print(S, T)
else:
    for i in range(M):
        if i % 2 == 0:
            S = i//2+1
            T = N-i//2
        else:
            S = N//2-1-i//2
            T = N//2+1+i//2
        print(S,T)
    



Measured memory_bytes: 9216
#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;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    vector<string> s(n); rep(i,n) cin>>s[i];
    set<string> st;
    rep(i,n) {
        st.insert(s[i]);
    }
    ct(st.size());
}


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

int main() {
	int x[5], dx, flag = 0;
	for (int i = 0; i < 5; i++) {
		cin >> x[i];
	}
	cin >> dx;
	sort(x, x + 5);
	if (x[4] - x[0] > dx) flag = 1;
	if (flag == 1) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <string>

using namespace std;


long long N, A, B;
long long dif;
long count;
long long answer;

long long temp;
vector <long long> v;
long tmin, tmax;
long amin, amax;

//差が1になるまで探す
void search(long long T){
	long long times = 0;
	for (int i = 0; i < N  ; i++){
		if (v[i] - B*T < 0){
			break;
		}
		times += (v[i] -B*T+(A-B-1)) / (A-B);
	}
	//回数超過
	if (times > T){
		amin = T;
		if (amax - amin != 1){
			search(amin + (amax - amin) / 2);
		}
	}
	else{
		amax = T;
		if (amax - amin != 1){
			search(amin + (amax - amin) / 2);
		}
	}
}

int main()
{


	cin >> N >> A >> B;
	dif = A - B;
	//確保出来る？
	for (int i = 0; i < N; ++i){
		cin >> temp;
		v.push_back(temp);
	}

	//降順ソート
	sort(v.begin(), v.end(), greater<long long>());

	//攻撃回数Tに関する2分探査で最小のTをもとめていく

	tmin = 0;	
	tmax = v[0] + (B - 1) / B;
	
	amin = tmin;	//倒しきれない最大値
	amax = tmax;	//倒しきれる最小値
	//min,maxを更新していって,min,maxの差が1になったら終わり
	//そのときのmaxが答え

	search(tmax / 2);


	cout << amax;


	return 0;
}

Measured memory_bytes: 1400
##======================================python3
import sys
import collections
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
import itertools

class Run:
    def build(gv):
        gv.N, gv.M = map(int, input().split())

    def solve(gv):
        ans = 0
        
        p = [0]*gv.N
        q = [0]*gv.M
        ans += len(list(itertools.combinations(p, 2)))
        ans += len(list(itertools.combinations(q, 2)))
        
        print (ans)
        
if __name__ == '__main__':
    run = Run()
    run.build()
    run.solve()


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin>>x;
	if(x>=30){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
int lcm(int a, int b){
  return a / gcd(a,b) * b;
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  int n; cin >> n;
  int mi = INF;
  int cnt = 0;
  rep(i,n){
    int t; cin >> t;
    if(t < mi){
      mi = t;
      cnt++;
    }
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
n, k = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)
used = Hash.new(false)

cyc = []
n.times do |i|
  cur = i
  if used[cur]
    next
  end

  q = []  
  while !used[cur]
    used[cur] = true
    q << c[cur]
    cur = p[cur] - 1
  end
  cyc << q
end

res = []
cyc.each do |cs|
  l = cs.size
  dp = [0]
  ct = Array.new(l, 0)

  l.times do |w|
    l.times do |i|
      ct[i] += cs[(i + w) % l]
    end
    dp << ct.max
  end

  if k <= l
    res << dp[1..k].max
  elsif dp[-1] <= 0
    res << dp[1..l].max
  else
    res << dp[-1] * ((k - 1) / l) + dp[1..((k - 1) % l + 1)].max
  end
end
puts res.max

Measured memory_bytes: 15320
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i, j, N-i-j)
            exit()

print('-1 -1 -1')

Measured memory_bytes: 2940
#include<iostream>
#include<set>
#include<string>
using namespace std;

int main() {
	int N;
	string W;
	cin >> N >> W;
	set<string> s;
	s.insert(W);
	char last = W[W.size() - 1];
	for (int i = 1;i < N;++ i) {
		cin >> W;
		if (last != W[0]) { // しりとりに反している
			cout << "No";
			return 0;
		}
		s.insert(W);
		last = W[W.size() - 1];
	}
	if (s.size() == N) cout << "Yes";
	else cout << "No"; // 同じ単語がある
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

実際に調べてみるだけ
同単語判定はsetを使うと楽
*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,i;
	char op;
	for(;;){
		cin>>a>>op>>b;
		if(op=='?')break;
		if(op=='+'){
			cout<<a+b<<endl;
		}else if(op=='-'){
			cout<<a-b<<endl;
		}else if(op=='*'){
			cout<<a*b<<endl;
		}else{
			cout<<a/b<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 3088
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
 
 
const ll INF = 1e18;
const ll N =(300+5); // TODO : change value as per problem
const ll MOD = 1e9+7;

void solve(){
    ll x,y;
    cin >> x >> y;
    if(x%y != 0){
        cout << x << endl;
    }
    else cout << -1 << endl;
    // for(int i = x;i<=200;i++){
    //     if(i%x==0 && i%y!=0){
    //         cout << i << endl;
    //     }
    // }
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    

 
     ll tt=1;   
    while(tt--){    
        solve();
    }    
}

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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li table[26];

int main() {
	li h, w;
	cin >> h >> w;
	rep(i, h) {
		string s;
		cin >> s;
		rep(i, sz(s)) {
			table[s[i] - 'a']++;
		}
	}
	li needs_4 = (h / 2) * (w / 2);
	li needs_2 = 0;
	if (h % 2 > 0) {
		needs_2 += (w / 2);
	}
	if (w % 2 > 0) {
		needs_2 += (h / 2);
	}

	// process needs_4
	while (needs_4 > 0) {
		bool decreace = false;
		rep(i, 26) {
			if (table[i] >= 4) {
				table[i] -= 4;
				needs_4--;
				decreace = true;
			}
			if (needs_4 <= 0) break;
		}
		if (!decreace && needs_4 > 0) {
			puts("No");
			return 0;
		}
	}

	// process needs_2
	while (needs_2 > 0) {
		bool decreace = false;
		rep(i, 26) {
			if (table[i] >= 2) {
				table[i] -= 2;
				needs_2--;
				decreace = true;
			}
			if (needs_2 <= 0) break;
		}
		if (!decreace && needs_2 > 0) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");

	return 0;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
#include <iostream>
#include <vector>
using namespace std;

int counter = 0;
const int infi = 1000000000;
void merge(int A[], int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];
  for(int i = 0; i<n1; i++){
    L[i] = A[left + i];
  }
  for(int i = 0; i<n2; i++){
    R[i] = A[mid + i];
  }
  L[n1] = infi;
  R[n2] = infi;
  int countL = 0, countR = 0;
  for(int i = left; i < right; i++){
    if(L[countL] <= R[countR]){
      A[i] = L[countL];
      countL++;
    }
    else{
      A[i] = R[countR];
      countR++;
    }
    counter++;
    //cout << A[i] << " ";
  }
  //cout << endl;
}



void mergeSort(int A[], int left, int right){
  if (left+1 < right) {
    int mid = (left+right)/2;
    //????????¨???????????§5/2 = 2?????????
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}


int main(){
  int n;
  cin >> n;
  int S[n];
  for(int i=0; i<n; i++){
    cin >> S[i];
  }//????????????????????????
  //S[n] = 123456;
  mergeSort(S,0,n);
  for(int i=0; i<n-1; i++){
  cout << S[i] << " ";
  }
  cout << S[n-1] << endl;
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
char ss[N]={};
char *s = ss+2;
int a[N][2]={};

int main(){
	scanf("%s", s);
	int n = strlen(s);
	a[n][0] = a[n][1] = 0;
	a[n+1][0] = a[n+1][1] = INT_MIN;
	for(int i = n-1; i>=0; i--){
		REP(j, 2){
			REP(k, 2){ // use k letters
				if(j != k){
					DEBUG("[%d][%d]=[%d][%d]+1\n", i, j, i+k, k);
				 	LAR(a[i][j], a[i+k+1][k] + 1);
				}
				else{
					bool ok = true;
					REP(l, j+1){
						if(s[i - (j+1) + l] == s[i + l]) ok = false;
					}
					if(ok){
						DEBUG("[%d][%d]=[%d][%d]+1\n", i, j, i+k+1, k);
						LAR(a[i][j], a[i+k+1][k] + 1);
					}
				}
			}
		}
	}
	REP(i, n+1) DEBUG("%2d ", i); DEBUG("\n");
	REP(i, n+1) DEBUG("%2d ", a[i][0]); DEBUG("\n");
	REP(i, n+1) DEBUG("%2d ", a[i][1]); DEBUG("\n");
	printf("%d\n", max(a[0][0], a[0][1]));
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define INF 1234567890
using namespace std;
int cou;
void merge(int *,int,int,int);
void mergesort(int *,int,int);
int main(){
  int n;
  int a[500005];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];

  }
  mergesort(a,0,n);
  for(int i=0;i<n;i++){
    if(i)cout << " ";
    cout << a[i];

  }
  cout << endl;
  cout << cou << endl;
  return 0;
}

  
void merge(int *a,int l,int m,int r){
  int n1 = m - l;
  int n2 = r - m;
  vector<int> L(n1+1);
  vector<int> R(n2+1);
  for(int i=0;i<n1;i++){
    L[i]=a[l+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=a[m+i];
  }
  L[n1]=INF;
  R[n2]=INF;
  int i=0;
  int j=0;
  for(int k=l;k<r;k++){
    if(L[i]<=R[j]){
      a[k]=L[i];
      i++;
    }
    else{
      a[k]=R[j];
      j++;
    }
    cou ++;
  }
}

void mergesort(int *a,int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(a,l,m);
    mergesort(a,m,r);
    merge(a,l,m,r);
  }
}

  

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

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

    for(int i=N-2;i>=0;i--){
        if(h[i]-h[i+1]>=2){
            cout<<"No"<<endl;
            return 0;
        }
        if(h[i]-h[i+1]==1){
            h[i]--;
        }
    }   
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 640
import sys
import math

N, H = map(int, input().split())
D = [list(map(int, input().split())) for i in range(N)]
D = sorted(D, key=lambda x:x[1])
D = D[::-1]
aMax = sorted(D, key=lambda x:x[0])[-1][0]

damage = 0
ans = 0
for d in D:
    if d[1] <= aMax:
        ans += math.ceil((H-damage) / aMax) 
        print(ans)
        sys.exit()
    damage += d[1]
    ans += 1
    if damage >= H:
        print(ans)
        sys.exit()
ans += math.ceil((H-damage) / aMax) 
print(ans)

Measured memory_bytes: 29668
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
bool cmp(int x , int y)
{
	return x > y;
}
char a[105], b[105];
int c[105], d[105];
int main()
{
	scanf("%s",a);
	scanf("%s",b);	
	for(int i = 0; a[i] != '\0'; i++)
	{
		c[i] = a[i];
	}
	for(int i = 0; b[i] != '\0'; i++)
	{
		d[i] = b[i];
	}
	int len1 = strlen(a);
	int len2 = strlen(b);
	int len3 = max(len1, len2);
	sort(c, c + len1);
	sort(d, d + len2, cmp);
	for(int j = 0; j <= len3; j++)
	{
		if(c[j] < d[j] || ((c[j] == 0) && (d[j] != 0)))
		{
			printf("Yes\n");
			break;
		}
		if(c[j] > d[j])
		{
			printf("No\n");
			break;
		}
		if(c[j] == d[j]) continue;
	}
	if(strcmp(a,b) == 0)
	{
		printf("No\n");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>

using namespace std;

string target = "ACGT";

int main()
{
    string S;
    int cnt = 0;

    int iMax = 0;

//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    
    cin >> S;

    for(int i = 0; i < S.size(); i++)
    {
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')cnt++;
        else
        {
            iMax = max(iMax, cnt);
            cnt = 0;
        }
    }
    //末尾の処理
    iMax = max(iMax, cnt);

    cout << iMax << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
using ll = long long;
ll a[200000], s[200000];
int main() {
    ll N, S = 0;
    cin >> N;
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
        s[i] = i > 0 ? s[i - 1] + a[i] : a[i];
        S += a[i];
    }
    ll min = INT_MAX;
    for (int i = 0; i < N - 1; i++) {
        ll tmp = abs(2 * s[i] - S);
        if (tmp < min) min = tmp;
    }
    cout << min << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int val[] = { 10, 50, 100, 500 };

int main(){
	ios::sync_with_stdio(false);

	int n;
	bool f = true;
	while (cin >> n, n){
		if (!f) cout << endl;
		f = false;
		int cnt[4] = {};
		rep(i, 4) cin >> cnt[i];
		int ret = -n;
		rep(i, 4) ret += val[i] * cnt[i];
		int res[4] = {};
		for (int i = 3; i >= 0; --i){
			res[i] += ret / val[i];
			ret %= val[i];
		}
		rep(i, 4) cnt[i] -= min(cnt[i], res[i]);
		rep(i, 4){
			if (cnt[i]) cout << val[i] << ' ' << cnt[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }



struct UnionFind{
	vector<int> data;
	
	UnionFind(int n){
		data.assign(n,-1);
	}
	
	bool unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return(false);
		if(data[x]>data[y]) swap(x,y);
		data[x]+=data[y];
		data[y]=x;
		return(true);
	}
	
	int find(int k){
		if(data[k]<0) return(k);
		return(data[k]=find(data[k]));
	}
	
	int size(int k){
		return(-data[find(k)]);
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> p(n);
	rep(i,n){
		cin >> p.at(i);
		p.at(i)--;
	}
	UnionFind uf(n);
	rep(i,m){
		int x,y;cin >> x >> y;
		x--;y--;
		uf.unite(x,y);
	}
	int ans = 0;
	rep(i,n){
		if(p.at(i) == i) ans++;
		else if(uf.find(p.at(i)) == uf.find(i)) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)


ll solve_inversion(vector<int> &v){
    if(v.size()==1)return 0;
    
    vector<int> a(v.begin(),v.begin()+v.size()/2);
    vector<int> b(v.begin()+v.size()/2,v.end());
    
    ll cnt = solve_inversion(a) + solve_inversion(b);
    
    int l=0,r=0,p=0;
    int nl = a.size(), nr = b.size();

    while(1){
        if(l==nl && r==nr)break;
        if(r==nr || (l<nl && a[l]<=b[r])){
            v[p++]=a[l++];
        }else{
            cnt+=nl-l;
            v[p++]=b[r++];
        }
    }
    
    return cnt;
}

signed main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)scanf("%d",&v[i]);
    
    cout<<solve_inversion(v)<<endl;
}

Measured memory_bytes: 5392
def solve():
    n=int(input())
    b=[int(i) for i in input().split()]
    ans=[]
    for i in range(n):
        flag=False
        for i in range(len(b),0,-1):
            if b[i-1]==i:
                ans.append(i)
                del(b[i-1])
                flag=True
                break
        if flag==False:
            print(-1)
            return
    for i in ans[::-1]:
        print(i)

solve()

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/
using Graph = vector<bitset<10>>;
ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
 
//繰り返し二乗法
ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
  
}
int main(){
   ll n,a,b;
   cin >> n >> a >> b;

   ll ans = 0;
   ans += calc(2,n,P) - 1;
   
   ll nkaia = 1;//nCaの分子
   for(ll i = n ;i>=n-(a-1); i--){
     nkaia *= i;
     nkaia %= P;
   }
   ll nCa = (nkaia * calc(factorial(a),P-2,P))%P;

   ll nkaib = 1;//nCbの分子
   for(ll i = n ;i>=n-(b-1); i--){
     nkaib *= i;
     nkaib %= P;
   }
   ll nCb = (nkaib * calc(factorial(b),P-2,P))%P;

   ans -= nCa;
   if(ans < 0) ans += P;

   ans -= nCb;
   if(ans < 0) ans += P;
   cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
const int N = 100100;
int main()
{
	vector<int> x(3, 0);
	scanf("%d %d %d", &x[0],&x[1],&x[2]);
	sort(x.begin(), x.end());
	printf("%d\n", x[0] + x[1]);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = {}
for i in range(N):
    k = int(input())
    if not k in a.keys():
        a[k] = 0
    a[k] += 1
cnt = 0
for i in a.keys():
    if a[i] % 2 == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 15068
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
		int syaink = sc.nextInt();
      int[] buka=new int[syaink];
      for(int i=0;i<buka.length;i++){
        buka[i]=0;
      }
      for(int i=0;i<syaink-1;i++){
        int a=sc.nextInt();
        buka[a-1]+=1;
      }
      for(int i=0;i<buka.length;i++){
      System.out.println(buka[i]);
	}
}
}

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

using namespace std;

#define ll long long

int main(){
	int N;
	scanf("%d",&N);
	int good=0;
	int bad=0;
	for(int i=0;i<N;i++) {
		int x;
		scanf("%d",&x);
		if(x%4==0) {
			good++;
		}else if(x%2==0){
			bad++;
		}
	}
	if(good*2 + bad >= N || (good*2+1)>=N) puts("Yes");
	else puts("No");
	return 0;
}




Measured memory_bytes: 3692
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

const LL NN=100*1000+1;
const LL mod=1000*1000*1000+7;
LL U=1LL<<60;
vector<P> path[NN];
LL dist[NN];
LL dist2[NN];
LL num[NN];
LL num2[NN];

int main() {
	int N,M;
	cin >> N >> M;
	int S,T;
	cin >> S >> T;
	S--;T--;
	for(int i=0;i<M;i++){
		int u,v,d;
		cin >> u >> v >> d;
		u--;
		v--;
		path[u].push_back(P(v,d));
		path[v].push_back(P(u,d));
	}
	priority_queue<P,vector<P>,greater<P> > pq;
	for(int i=0;i<N;i++){
		dist[i]=dist2[i]=U;
		num[i]=0;
	}
	pq.push(P(0,S));
	dist[S]=0;
	vector<int> order;
	while(pq.size()){
		int p=pq.top().second;
		LL d=pq.top().first;
		pq.pop();
		if(dist[p]<d)continue;
		order.push_back(p);
		//cout << p << endl;
		for(auto n:path[p]){
			if(dist[n.first]>n.second+d){
				dist[n.first]=n.second+d;
				pq.push(P(n.second+d,n.first));
			}
		}
	}

	pq.push(P(0,T));
	dist2[T]=0;
	vector<int> order2;
	while(pq.size()){
		int p=pq.top().second;
		LL d=pq.top().first;
		pq.pop();
		if(dist2[p]<d)continue;
		order2.push_back(p);
		for(auto n:path[p]){
			if(dist2[n.first]>n.second+d){
				dist2[n.first]=n.second+d;
				pq.push(P(n.second+d,n.first));
			}
		}
	}
	LL t=dist[T];
	num[S]=1;
	num2[T]=1;
	vector<LL> vs;
	for(int r:order2){
		for(auto p:path[r]){
			if(dist2[p.first]==dist2[r]+p.second){
				num2[p.first]+=num2[r];
				num2[p.first]%=mod;
			}
		}
	}
	LL ng=0;
	for(int r:order){
		if(dist[r]*2==t&&dist[r]+dist2[r]==t){
			ng+=num[r]*num[r]%mod*num2[r]%mod*num2[r]%mod;
			ng%=mod;
		}
		//cout << r << ": " << dist[r] << endl;
		for(auto p:path[r]){
			if(dist[p.first]==dist[r]+p.second){
				num[p.first]+=num[r];
				num[p.first]%=mod;
				if(dist[r]*2<t&&t<dist[p.first]*2&&dist[r]+dist2[r]==t&&dist[p.first]+dist2[p.first]==t){
					ng+=num[r]*num[r]%mod*num2[p.first]%mod*num2[p.first]%mod;
					ng%=mod;
				}
			}
		}
	}
	cout << (num[T]*num[T]%mod+mod-ng)%mod << endl;

	return 0;
}



Measured memory_bytes: 18200
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

;; a1=0, a2=c21-c11, a3=c31-c21+a2
;; b1=c11, b2=c12, b3=c13
(defun main ()
  (let* ((c11 (read))
         (c12 (read))
         (c13 (read))
         (c21 (read))
         (c22 (read))
         (c23 (read))
         (c31 (read))
         (c32 (read))
         (c33 (read))
         (a1 0)
         (a2 (- c21 c11))
         (a3 (+ (- c31 c21) a2))
         (b1 c11)
         (b2 c12)
         (b3 c13))
    (if (and (= c11 (+ a1 b1))
             (= c12 (+ a1 b2))
             (= c13 (+ a1 b3))
             (= c21 (+ a2 b1))
             (= c22 (+ a2 b2))
             (= c23 (+ a2 b3))
             (= c31 (+ a3 b1))
             (= c32 (+ a3 b2))
             (= c33 (+ a3 b3)))
        (println "Yes")
        (println "No"))))

#-swank(main)


Measured memory_bytes: 27620