akhauriyash/Code-Regression huggingface dataset:
while True:

    n, m = [int(i) for i in input().split()]
    if n == 0 and m == 0:
        break

    p = [int(i) for i in input().split()]
    p.sort()
    p.reverse()

    ans = 0
    for i in range(len(p)):
        if (i+1) % m > 0:
            ans = ans + p[i]

    print(ans)




Measured memory_bytes: 5716
// In The Name Of God
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e5 + 20;
int a[3][N], dp[N][3], n;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[0][i] >> a[1][i] >> a[2][i];
	dp[0][0] = max(a[1][0], a[2][0]);
	dp[0][1] = max(a[0][0], a[2][0]);
	dp[0][2] = max(a[0][0], a[1][0]);
	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1] + a[1][i], dp[i - 1][2] + a[2][i]);
		dp[i][1] = max(dp[i - 1][0] + a[0][i], dp[i - 1][2] + a[2][i]);
		dp[i][2] = max(dp[i - 1][0] + a[0][i], dp[i - 1][1] + a[1][i]);
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
}



Measured memory_bytes: 2560
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    c_num = 8 # カラー数の上限
    c = [0]*c_num
    all_color = 0
    a = list(int(_) for _ in input().split())
    for i in range(len(a)):
        index = a[i]//400
        if(index < 8):
            c[index] = 1
        else:
            all_color +=1
    min_color = max(sum(c),1)

    # for i in range(len(c)):
    #     if(c[i]==0 and all_color>0):
    #         c[i] = 1
    #         all_color -=1
    max_color = sum(c) + all_color
    print(min_color,max_color)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int>x(4);
  for(int i=0;i<4;i++)cin>>x.at(i);
  sort(x.begin(),x.end());
  if(x.at(0)==1&&x.at(1)==4&&x.at(2)==7&&x.at(3)==9)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/arc094_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N = 3;

  vector<int> d(N);
  rep(i, N) { cin >> d[i]; }
  sort(d.begin(), d.end());

  int a = d[0];
  int b = d[1];
  int c = d[2];

  ll ans = 0;
  if ((b - a) % 2 == 0) {
    ans += (b - a) / 2;
    a = b;
  } else {
    ans += (b - a) / 2 + 1;
    c++;
  }

  ans += c - b;

  cout << ans << endl;
}

Measured memory_bytes: 3620
import itertools

a1, b1, c1 = map(int, input().split())
a2, b2, c2 = map(int, input().split())
a3, b3, c3 = map(int, input().split())

checker = [
(a1,b1,c1),
(a2,b2,c2),
(a3,b3,c3),
(a1,a2,a3),
(b1,b2,b3),
(c1,c2,c3),
(a1,b2,c3),
(c1,b2,a3)
]

N = int(input())

numbers = []
for i in range(N):
  numbers.append(int(input()))
ans="No"
tuples = itertools.permutations(numbers,3)
for i in tuples:
  if i in checker:
    ans = "Yes"
    break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
ll a,b,n;
ll f(ll x){
  return floor((a * x) / b) - a * floor(x / b);
}
int main(){
  cin >> a >> b >> n;
  ll ans = 0;
  cout << f(min(b - 1,n)) << endl;
  return 0;
}


Measured memory_bytes: 3672
n=int(input())
a=list(map(int,input().split()))
b_0=0
b_2=0
b_4=0
for i in a:
    if i%4==0:
        b_4+=1
    elif i%2==0:
        b_2+=1
    else:
        b_0+=1
if b_2==0:
    if b_0<=b_4+1:
        print("Yes")
    else:
        print("No")
else:
    if b_0<=b_4:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int n, y;
	cin >> n >> y;
	for(int i = 0; i <= y / 10000; i++){
			int rem = y - i * 10000;
			for(int j = 0; j <= rem / 5000; j++){
					int remrem = rem - j * 5000;
					if(remrem == 1000 * (n - i - j)){
							cout << i << " " << j << " " << remrem / 1000 << endl;
							return 0;
					}
			}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 1005

const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int dp[ARRAY_MAX];//dp[i]:=重さがiとなる場合の最大価値

int main() {

	int W;
	int cnt = 1;
	while (cin >> W, W)
	{
		int n;
		char c;
		cin >> n;
		vector<int> v(n), w(n);
		for (int i = 0; i < n; i++)
		{
			cin >> v[i] >> c >> w[i];
		}

		for (int i = 0; i < ARRAY_MAX; i++)
		{
			dp[i] = 0;
		}

		for (int i = 0; i < n; i++) 
		{
			for (int j = W; j >= 0; j--)
			{
				if (j - w[i] >= 0)
				{
					dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
				}
			}
		}
		int ans_w = 0;
		int ans_v = 0;

		for (int i = 0; i <= W; i++)
		{

			if (ans_v < dp[i])
			{
				ans_v = dp[i];
				ans_w = i;
			}
		}
		cout << "Case " << cnt << ":" << endl;
		cout << ans_v << endl << ans_w << endl;
		cnt++;
		v.shrink_to_fit();
		w.shrink_to_fit();
	}
}


Measured memory_bytes: 3060
# ABC066C - pushpush (ARC077)
from collections import deque


def main():
    N, *A = map(int, open(0).read().split())
    B, x = deque(), int(N) & 1
    for i, a in enumerate(A, start=x):
        if i & 1:
            B.appendleft(a)
        else:
            B.append(a)
    print(*B)


if __name__ == "__main__":
    main()

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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

int main()
{
    llint r, d, x;
    ci >> r >> d >> x;

    rep(i, 0, 10) {
	co << (x = (r * x - d)) << en;
    }
  
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  double n, m;
  cin >> n >> m;
  vector<double> v(n, 0.0);
  double res = 0;
  rep(i, n){
    cin >> v[i];
    res += v[i];
  }
  res /= 4.0*m;
  // cout << res << endl;
  int ans = 0;
  rep(i, n){
    if(v[i] >= res) ans++;
  }
  if(m <= ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
int main()
{
    double d;
    std::cin >> d;
    double h,n,w;
    double x;
    double y;
    w = 0;
    for(h = 1; h <= 3500; h++)
    {
        for(n = h; n <= 3500; n++)
        {
            y = (4*h*n)-(d*n)-(d*h);
            if(y != 0)
            {
                w = (d*h*n)/y;
                if(y !=0 && w >= n && int(w) == w)
                {
                    std::cout << h << " " << n << " " << std::setprecision(12) << w << std::endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
   int x,a,b;
   int rest_x;
  
   scanf("%d\n%d\n%d\n", &x, &a, &b);
  
   rest_x = x - a;
   //printf("%d",rest_x);
   do{
     rest_x -= b;
   }while(rest_x >= 0);
   printf("%d", (rest_x + b));
 
  return 0;
}

Measured memory_bytes: 128
def dfs(seq):
    global ans
    if len(seq) == n:
        tmp = 0
        for i in range(q):
            if seq[b[i]] - seq[a[i]] == c[i]:
                tmp += d[i]
        ans = max(tmp, ans)
        return 
       
    if seq == []:
        start=0
    else:
        start = seq[-1]

    for i in range(start,m):
        dfs(seq+[i])

n,m,q = map(int,input().split())

a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int,input().split())
    a[i]-=1; b[i]-=1
    
ans = 0
dfs([])
print(ans)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 2010;
const long double PI = acos(-1);

bool f(ll n){
    ll l = n%10;
    while(n){
        if (abs(n%10 - l) > 1) return false;
        n/=10;
    }
    return true;
}

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> ans, a;

    for (int i=1; i<10; i++) a.push_back(i), ans.push_back(i);

    while(ans.size() < 100000){
        vector<ll> next;
        for (int i=0; i<10; i++){
            for (auto x: a){
                if (abs(x%10 - i) <= 1) {
                    next.push_back(x*10+i);
                    ans.push_back(x*10+i);
                }
            }
        }
        a = next;
    }

    sort(all(ans));
    cout << ans[n-1] << endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  string S; set<string> str_set;
  for (int i = 0; i < N; i++) {
    cin >> S;
    str_set.insert(S);
  }
  cout << str_set.size() << endl;
}

Measured memory_bytes: 19092
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

// cout << fixed << setprecision(12)

int main(){
  
  lint D; cin >> D;
  vi c(26); // contest 0-25
  for(lint i=0; i<26; i++) cin >> c[i];
  vvi s(D+1, vi(26)); // day 0-D
  for(lint d=1; d<=D; d++){
    for(lint j=0; j<26; j++){
      cin >> s[d][j];
    }
  }
  /*
  vi t(D+1); // day 0-D
  
  for(lint d=1; d<=D; d++){
    cin >> t[d];
    t[d]--;
  }
  */
  
  vi last(26,0);
  
  // lint ans = 0;
  vi ans(D+1);
  
  for(lint d=1; d<=D; d++){
    vi diff(26);
    
    for(lint i=0; i<26; i++){ // if contest i (0-25)
      // ans += s[d][t[d]];
      lint plus = s[d][i];
    
      // last[t[d]] = d;
      lint oldlast = last[i];
      last[i] = d;
    
      lint minus = 0;
    
      for(lint j=0; j<26; j++){
        // ans -= c[j] * (d - last[j]);
        minus += c[j] * (d - last[j]);
      }
      
      last[i] = oldlast;
      diff[i] = plus - minus;
    }
    
    vi oldiff = diff;
    sort(ALL(diff));
    lint t = -1;
    for(lint j=0; j<26; j++){
      if(oldiff[j] == diff[25]) t = j;
    }
    // cout << t+1 << endl;
    ans[d] = t+1;
    last[t] = d;
    
  }
  /*
  sort(ALL(c));
  lint tmp = 18; // delete suru kosuu
  for(lint j=0; j<tmp; j++) c.pop_back();
          
  for(lint d=1; d<=D; d++){
    cout << c[d%(26-tmp)] << endl;
  }
  */
  
  for(lint i=0; i<26; i++) last[i] = 0;
  
  lint score = 0;
  
  for(lint d=1; d<=D; d++){
    score += s[d][ans[d]];
    last[ans[d]] = d;
    for(lint j=0; j<26; j++){
      score -= c[j] * (d - last[j]);
    }
  }
  
  lint cnt = 0;
  while(cnt<6){
    lint rd = rand()%25;
    swap(ans[rd], ans[rd+1]);
    ////////
    lint score2 = 0;
    for(lint d=1; d<=D; d++){
      score2 += s[d][ans[d]];
      last[ans[d]] = d;
      for(lint j=0; j<26; j++){
        score2 -= c[j] * (d - last[j]);
      }
    }
    ////////
    if(score2 <= score){
      swap(ans[rd], ans[rd+1]);
    }else{
      // cout << score << endl << score2 << endl;
      score = score2;
      cnt++;
      
    }
  }

  
  for(lint d=1; d<=D; d++) cout << ans[d] << endl;
}
      
      
    
  
  
  
  


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int INF = 1<<30;

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> s(n), p(m);
    vector<int> ans(n);
    rep(i,n) cin >> s[i].first >> s[i].second;
    rep(i,m) cin >> p[i].first >> p[i].second;
    rep(i,n){
        int x = s[i].first, y = s[i].second;
        int minDis = INF;
        rep(j,m){
            int dis = abs(p[j].first-x) + abs(p[j].second-y);
            if (chmin(minDis, dis)) ans[i] = j+1;
        }
    }
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3608
using System;

namespace tes
{
    class Program
    {
        static void Main(string[] args)
        {
            double r = double.Parse(Console.ReadLine());

            double x = r * r * Math.PI;
            double y = (r * 2) * Math.PI;

            Console.WriteLine("{0:0.00000}"+" "+ "{1:f5}",x,y);
        }
    }
}

Measured memory_bytes: 9324
n = int(input())
al = list(map(int, input().split())) 

p = 10**9+7

sal = sum(al)  % p

import itertools
cumsum = list(itertools.accumulate(al))

temp = 0

for i in range(n):
    temp += (sal-cumsum[i]) *al[i]
    temp = temp % p

print(temp)

Measured memory_bytes: 31436
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<vector<int> > edge(n);
  REP(i, m) {
    int a, b; cin >> a >> b; --a; --b;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }
  vector<int> four;
  bool six = false;
  REP(i, n) {
    if (edge[i].size() & 1) {
      cout << "No\n";
      return 0;
    }
    if (edge[i].size() == 4) four.emplace_back(i);
    else if (edge[i].size() >= 6) six = true;
  }
  if (four.size() >= 3 || six) {
    cout << "Yes\n";
    return 0;
  }
  if (four.size() <= 1) {
    cout << "No\n";
    return 0;
  }
  function<void(int, int)> dfs = [&](int par, int ver) {
    for (int e : edge[ver]) if (e != par) {
      if (e == four.front()) {
        cout << "Yes\n";
        exit(0);
      }
      if (e != four.back()) dfs(ver, e);
    }
  };
  dfs(-1, four.front());
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int digitsum(int n) {
	int ret = 0;
	while (n > 0) {
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int K; cin >> K;
	int tmp = 1;
	int digit = 0;
	int m = 0;
	int prevx = 1;
	cout << 1 << endl;
	K--;
	while (K) {
		string S;
		string T;
		int tmp2 = tmp++;
		while (tmp2 > 0) {
			T.push_back((tmp2 % 10) + '0');
			tmp2 /= 10;
		}
		rep(i, T.length()) S.push_back(T[T.length() - 1 - i]);
		//if (tmp >= 101) digit--;
		rep(i, digit) S.push_back('9');
		int x = stoll(S);
		double X = (x) / (double)(digitsum(x));
		double prevX = (prevx) / double(digitsum(prevx));
		if (X >= prevX || S.length() == 1) {
			if (prevx != 1) {
				cout << prevx << endl;
				K--;
			}
		}
		prevx = x;
		//if (tmp >= 101) digit++;
		//cout << endl;
		if (tmp == max(10LL, m)) {
			// tmp = (m + 1) % max(10, (int)(pow(10, digit) + 0.5));
			tmp = (max(1LL, digit));
			digit++;
			m += 10;
		}
	}



	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * N
for i in range(1, N):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(i-K, 0), i))
print(dp[-1])

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    ll H, W;
    cin >> H >> W;

    if (H % 3 == 0 || W % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = H * W;
    rep(i, 2) {
        rep(g_w, W) {
            ll g = H * g_w;
            int w = W - g_w;
            int w_b = w / 2;
            int w_r = w - (w / 2);
            ll b = H * w_b;
            ll r = H * w_r;
            chmin(ans, abs(max(max(g, b), r) - min(min(g, b), r)));

            int h_b = H / 2;
            int h_r = H - h_b;
            b = h_b * (W - g_w);
            r = h_r * (W - g_w);
            chmin(ans, abs(max(max(g, b), r) - min(min(g, b), r)));
        }

        swap(H, W);
    }
    cout << ans << endl;
}

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;

int main() {
  char b;
  cin>>b;
  if(b=='T') cout<< 'A' <<endl;
  else if(b=='A') cout << 'T'<<endl;
  else if(b=='C') cout<<'G'<<endl;
  else cout<<'C'<<endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int n;
    cin >> n;
    int h[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    h[0] = h[1];
    int dp[n + 1];
    dp[0] = 0;
    dp[1] = 0;

    for (int i = 1; i < n; i++)
        dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i - 1] + abs(h[i + 1] - h[i - 1]));

    OP(dp[n]);

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct TNode
{
	int Id;
	TNode* Parent;
	TNode* NextSibling;
	TNode* FirstChild;
};

enum TNodeType {Root, InternalNode, Leaf};

void Create(int Id, vector<TNode*>& Nodes)
{
	TNode* Node = new TNode;
	*Node = {Id, NULL, NULL, NULL};
	Nodes[Id] = Node;
}

void CreateRelation(TNode* &ParentNode, TNode* &LastChild, TNode* &ChildNode)
{
	if(LastChild == NULL){
		ParentNode->FirstChild = ChildNode;
		ChildNode->Parent = ParentNode;
	}else{
		LastChild->NextSibling = ChildNode;
		ChildNode->Parent = LastChild->Parent;
	}
	LastChild = ChildNode;
}

vector<TNode*> Input()
{
	int n;
	cin >> n;
	vector<TNode*> Nodes(n, NULL);
	for(int i = 0; i < n; i++){
		int Id;
		cin >> Id;
		if(Nodes[Id] == NULL){
			Create(Id, Nodes);
		}
		int ChildCount;
		cin >> ChildCount;
		TNode* LastChild = NULL;
		for(int j = 0; j < ChildCount; j++){
			int ChildId;
			cin >> ChildId;
			if(Nodes[ChildId] == NULL){
				Create(ChildId, Nodes);
			}
			CreateRelation(Nodes[Id], LastChild, Nodes[ChildId]);
		}
	}
	return Nodes;
}

int GetDepth(TNode* Node)
{
    int depth = 0;
    while(Node->Parent){
        depth++;
        Node = Node->Parent;
    }
    return depth;
}

TNodeType GetType(TNode* Node)
{
    if(Node->Parent == NULL){
        return Root;
    }else if(Node->FirstChild == NULL){
        return Leaf;
    }else{
        return InternalNode;
    }
}

void OutputChildren(TNode* Node)
{
    if(Node->FirstChild == NULL){
        return;
    }
    Node = Node->FirstChild;
    cout << Node->Id; 
    while(Node->NextSibling){
        Node = Node->NextSibling;
        cout << ", " << Node->Id;
    }
}

void Output(const vector<TNode*>& Nodes)
{
	for(unsigned int i = 0; i < Nodes.size(); i++){
		cout << "node " << Nodes[i]->Id << ": ";
		if(Nodes[i]->Parent){
		    cout << "parent = " << Nodes[i]->Parent->Id << ", ";
		}else{
		    cout << "parent = -1, ";
		}
		cout << "depth = " << GetDepth(Nodes[i]) << ", ";
		if(GetType(Nodes[i]) == Root){
		    cout << "root, "; 
		}else if(GetType(Nodes[i]) == InternalNode){
		    cout << "internal node, ";    
		}else{
		    cout << "leaf, ";
		}
		cout << "[";
		OutputChildren(Nodes[i]);
		cout << "]" << endl;
	}
}

int main()
{
	vector<TNode*> Nodes = Input();
	Output(Nodes);
    return 0;
}

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

int main(){
    int n;cin>>n;
    vector<int> rank(n);
    for (int i = 0; i < n-1; i++)
    {
        int k;
        cin>>k;
        rank.at(k-1)++;
    }
    for (int i = 0; i < n; i++)
    {
        /* code */
        cout<<rank.at(i)<<endl;
    }
    
}

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

int main(){
  int N,sum=0;
  string A,B,C;
  cin>>N>>A>>B>>C;
  for(int i=0;i<N;i++){
    if(A.at(i)==B.at(i)){
      if(A.at(i)!=C.at(i)){
        sum++;
      }
    }else if(A.at(i)==C.at(i)){
      sum++;
    }else if(B.at(i)==C.at(i)){
      sum++;
    }else{
      sum+=2;
    }
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 256
N=int(input())
S=input()
 
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g
ans = ans * b
 
for i in range( N ):
    for j in range(i, N):
        k = 2 * j - i
        if (i < j) & (j < k) & (k < N) :
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                ans -= 1
 
print(ans)

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    char c;
    cin >> c;
    int a = 'A' + 'T';
    int b = 'C' + 'G';
    if (c == 'A' || c == 'T')
        cout << char(a - c);
    else
        cout << char(b - c);
    return 0;
}
                

Measured memory_bytes: 256
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
#      .      '                    Udit Gupta @luctivud         ,              
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            ##     ##  #######  # #  ######
                            ##     ##  ##   ##  ###    ##
                            ##     ##  ##    #  # #    ##
                            #########  #######  # #    ##
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printwsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end="tst, ")

MODPRIME = int(1e9+7); BABYMOD = 998244353;
# ################################ HELPER PROGRAMS USED ###################################
# ################################## MAIN STARTS HERE #####################################
# for _testcases_ in range(int(input())):
k, n = get_ints()
a = get_array()
a.sort()
maxdiff = - float('inf')
for i in range(n-1):
    maxdiff = max(maxdiff, abs(a[i] - a[(i+1)%n]))
maxdiff = max(maxdiff, k - a[-1] + a[0])
print(k - maxdiff)

# #########################################################################################
'''
THE LOGIC AND APPROACH IS BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
: DO NOT PLAGIARISE.
'''

Measured memory_bytes: 72180
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll dp[110][110000]={};
signed main(){
  ll n,W,ans=0;
  cin >> n >> W;
  ll w[n],v[n];
  for(int i=0;i<n;i++){
    cin >> w[i]>>v[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      dp[i+1][j] = dp[i][j];
      if(j-w[i]>=0){
        dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
        ans = max(ans,dp[i+1][j]);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 87424
import java.io.*;
import java.util.*;


public class Main {
    static long mod = 1000000000+7;
    static int maxn=2;
    static long[] f5ac, inv;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt();
        cell[] rec = new cell[n];
        for(int i=0;i<n;i++){
            String s = sc.next();
            int p = sc.nextInt();
            rec[i] = new cell(s,i+1,p);
        }
        Arrays.sort(rec);
        for(int i=0;i<n;i++) System.out.println(rec[i].idx);
    }
    static class cell implements Comparable<cell>{
        String city;
        int idx, score;
        public cell(String s, int i, int sc){
            city = s;
            idx = i; score = sc;
        }
        public int compareTo(cell c){
            if(!this.city.equals(c.city)) return this.city.compareTo(c.city);
            return -this.score+c.score;
        }
    }
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int gcd(int x, int y) {
	if(x < y) return (x == 0) ? y : gcd(y%x, x);
	return (y == 0) ? x : gcd(x%y, y);
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	int pl = 0;
	while(true) {
		int odd = 0, even = 0;
		for(int i = 0; i < N; i++)
			if(A[i] % 2) odd++;
			else even++;
		if(even % 2 != 0) break;
		if(odd != 1 && even % 2 == 0) {
			pl = 1-pl;
			break;
		}
		bool fail = false;
		for(int i = 0; i < N; i++) if(A[i] % 2) {
			if(A[i] == 1) {
				fail = true;
				break;
			}
			A[i]--;
			int g = 0;
			for(int j = 0; j < N; j++) g = gcd(g, A[j]);
			for(int j = 0; j < N; j++) A[j] /= g;
			break;
		}
		pl = 1-pl;
		if(fail) break;
	}
	cout << (pl ? "Second\n" : "First\n");
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define DB(x)            cout << '>' << #x << ':' << x << endl;
#define DB2(x,y) 	 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define rep(i,a,b)       for (ll i = a; i < b; i++)
#define repr(i,a,b)      for (ll i = a; i >= b; i--)
#define pb               push_back
#define F                first
#define S                second
#define mp               make_pair
#define MOD              1000000007
#define MAX              1e9
#define MIN              -1e9
#define vec(i)           vector<i>
#define PLL           	 pair<ll,ll>
#define mem(a,v)         memset(a,v,sizeof(a))
#define pf               printf
#define sc               scanf
#define _s               "%s"
#define _d               "%d"
#define _ll              "%lld"
#define _c               "%c"
#define FAST_IO          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define min(a,b)         a>b?b:a
#define max(a,b)         a>b?a:b
typedef long long ll;
using namespace std;
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	bool f=false;
	if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5))
		cout<<"YES";
	else
		cout<<"NO";

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int mod = 1000000007;
int main() {
	int N;
	cin >> N;
	vector<int> X(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i];
		int xa = X[i] + Y[i];
		int xb = X[i] - Y[i];
		X[i] = xa; Y[i] = xb;
	}
	int xl = *min_element(X.begin(), X.end());
	int xr = *max_element(X.begin(), X.end());
	int yl = *min_element(Y.begin(), Y.end());
	int yr = *max_element(Y.begin(), Y.end());
	cout << max(xr - xl, yr - yl) << endl;
	return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)


int main(){
  ll n,m;
  cin >> n >> m;
  ll res = 0;
  res = min(n,m/2);
  if (2*n <= m){
    m -= 2*n;
    res = max(res,res+m/4);
  }
  cout << res << endl;  

  return 0;
}

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

const int INF = 1e9;

int n;
int d[102][102];

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

int main()
{
    int m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        fill(d[i], d[i] + n, INF);
    }
    int a[1005], b[1005], c[1005];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    WarshallFloyd();
    int ans = 0;
    for(int i = 0; i < m; i++){
        if(d[a[i]][b[i]] < c[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a <= b) {
			System.out.println(a);
		} else {
			System.out.println(a - 1);
		}
	}
}

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

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int res = 0;
	rep(i, n - 1) {
		if (s[i] == s[i + 1]) res++;
	}
	int ans = min(res + 2 * k, n - 1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i ++)
#define for1(i, n) for (int i = 1; i <= n; i ++)
#define repn(i, n) for (int i = n-1; i >= 0; i --)
#define rep1(i, n) for (int i = n; i >= 1; i --)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define f first
#define s second
using namespace std;
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef queue<int> qi;
typedef queue<pii> qpii;

void test_case() {
	int n; cin >> n;
	vll ile(100005);
	ll sum = 0;
	forn (i, n) {
		int x; cin >> x;
		sum += x;
		ile[x] ++;
	}
	int q; cin >> q;
	while (q--) {
		ll a, b; cin >> a >> b;
		sum -= ile[a] * a;
		sum += ile[a] * b;
		ile[b] += ile[a];
		ile[a] = 0;
		cout << sum << '\n';
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; 
	//cin >> q;
	while (q--) {
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3988
w=input()
l=[0 for _ in range(26)]
Flag=True
for i in w:
    num=ord(i)-97
    #print(num)
    l[num]+=1
for i in l:
    if i%2==1:
        Flag=False
if Flag:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 9036
M = int(input())
if M%10==2 or M%10==4 or M%10==5 or M%10==7 or M%10==9:
    print('hon')
elif M%10==0 or M%10==1 or M%10==6 or M%10==8:
    print('pon')
else:
    print('bon')

Measured memory_bytes: 61644
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;
typedef long long ll;

int dp[2][1 << 25];

vector <bool> Xor(vector<bool>& a, vector<bool>& b) {
	vector<bool> ret;
	ret.resize(a.size());
	for (int i = 0; i < ret.size(); i++) {
		ret[i] = a[i] ^ b[i];
	}
	return ret;
}

int main() {
	while (1) {
		int n, m;
		cin >> n >> m;
		if (n + m == 0)break;

		if (n <= 20) {
			vector<bool> b[500];
			for (int i = 0; i < n; i++) {
				string s;
				cin >> s;
				for (int j = 0; j < m; j++) {
					if (s[j] == '1')b[i].push_back(true);
					else b[i].push_back(false);
				}
			}
			//bit全探索
			int ans = 0;
			for (int i = 0; i < (1 << n); i++) {
				vector<bool> tmp(m);
				int cnt = 0;
				for (int j = 0; j < m; j++)tmp[j] = false;
				for (int j = 0; j < n; j++) {
					if ((i >> j) & 1) {
						tmp = Xor(tmp, b[j]), cnt++;
					}
				}
				if (!accumulate(tmp.begin(), tmp.end(), 0))ans = max(ans, cnt);
			}
			cout << ans << endl;
		}
		else {
			ll B[500] = {};
			for (int i = 0; i < n; i++) {
				string s;
				cin >> s;
				for (int j = 0; j < s.size(); j++) {
					if (s[j] == '1')B[i] += (1 << (s.size() - j - 1));
				}
			}

			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < (1 << m); j++) {
					dp[i][j] = -114514;
				}
			}
			dp[0][0] = 0;
			int* now = dp[0];
			int* next = dp[1];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < (1 << m); j++) {
					if (now[j] == -114514)continue;
					next[j ^ B[i]] = max(next[j ^ B[i]], now[j] + 1);
					next[j] = max(next[j], now[j]);
					now[j] = -114514;
				}
				swap(now, next);
			}
			cout << now[0] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 68764
#include <vector>
#include <iostream>
using namespace std;
int n, m, c;
int main() {
	while (cin >> n >> m, n | m) {
		vector<int> v(m + 1); v[0] = n;
		int ret = 0;
		while (v[m] == 0) {
			vector<int> w(m + 1);
			for (int i = 0; i < m; i++) {
				w[i + 1] += v[i] / 2;
				w[0] += v[i] / 2;
				w[i] += v[i] % 2;
			}
			v = w; ret++;
		}
		cout << "Case " << ++c << ": " << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

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

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;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n];
    bool flg = true;
    for( int i = 0; i < n; ++i ) {
        cin >> a[i];

        if( i + 1 < a[i] ) flg = false;

    }

    
    //手順の探索
    vector< int > v;
    for( int i = 0; i < n; ++i ) {
        int cnt = 1;
        int max_v = -1;
        int max_p = -1;
        for( int j = 0; j < n; ++j ) {
            if( cnt == a[j] ) {
                if( max_v < a[j] ) {
                    max_v = a[j];
                    max_p = j;

                }
            }
            if( a[j] != -1 ) ++cnt;
        }

        if( max_p >= 0 ) a[max_p] = -1;
        v.pb( max_v );
    }


    if( flg ) {
        for( int i = v.size() -1; i >= 0; --i ) cout << v[i] << endl;
    
    } else cout << -1 << endl;


    return 0;
}



Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d %d",&n,&m);
	FOR{
		scanf("%d",&k);
		if(k>=m)cev++;
	}
	printf("%d\n",cev);
	return 0;
}


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

#define F first
#define S second
#define x1 privet1
#define x2 privet2
#define y1 privet3
#define y2 privet4
#define left privet6

using namespace std;
typedef long long ll;

const int max_n = 200011, log_n = 32, max_m = 111, mod = 1000000007, inf = 1000111222;

int a, b, c;

int main() {
    // freopen("input.txt", "r", stdin);
    cin >> a >> b;
    c = a + b;
    if (a % 3 == 0 || b % 3 == 0 || c % 3 == 0) {
        cout << "Possible\n";
    } else {
        cout << "Impossible\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <stdio.h>
using namespace std; 
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define ll long long int
#define REPI(a, b, i, inc) for(ll i = a; i < b; i = i + inc)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define test ll t; cin>>t; while(t--)
#define testi ll t; cin>>t; REP(tc,1,t+1)
#define vec vector
#define veci vector<ll>
#define pi pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define uset unordered_set
#define umap unordered_map

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("op.txt","w",stdout);
    #endif
	
	
    ll n;
    ll k;
    cin>>n>>k;
    ll arr[n];
    REP(i,0,n) cin>>arr[i];
    //priority_queue<pair<int,int>> q;
   
    REP(i,k,n)
    {
    	if(arr[i]>arr[i-k])
            cout<<"Yes"<<endl;
        else
        	cout<<"No"<<endl;


    }


	
	return 0;


}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =1000000007;
const int INV2 = (MOD+1)/2;



     signed main(){
 int n;
 cin>>n;n++;
 vector<int> x,y,z;
 int k=0;while((1ll<<k)<=n)k++;
 k--;
 int b=100;
 for(int i=0;i<k;i++){
   if(n&(1ll<<i)){
     y.push_back(b);
     z.push_back(b);
     b--;
   }
   x.push_back(i+1);
   z.push_back(i+1);
 }
 cout<<x.size()+y.size()+z.size()<<endl;
 for(int i=0;i<x.size();i++)cout<<x[i]<<' ';
 for(int i=y.size()-1;i>=0;i--)cout<<y[i]<<' ';
 for(int i=0;i<z.size();i++)cout<<z[i]<<' ';
 cout<<endl;



}


        


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;

int H, W, WHITE = 0;
vector<string> s;
vector<bitset<51>> used(51);

int main(void){
    
    scanf("%d %d", &H, &W);
    for(int i = 0; i < H; ++i){
        string a; cin >> a; s.push_back(a);
        for(int j = 0; j < a.size(); ++j) if(a[j] == '.') ++WHITE;
    }
    
    queue<T> que;
    que.push(make_tuple(0, 0, 0));
    
    int dist = -1;
    while(!que.empty()){
        
        int y, x, cnt; tie(y, x, cnt) = que.front(); que.pop();
        
        if(y < 0 || H <= y || x < 0 || W <= x) continue;
        if(s[y][x] == '#') continue;
        if(used[y][x]) continue;
        if(y == H - 1 && x == W - 1){ dist = cnt; break; }
        
        used[y][x] = true;
        que.push(make_tuple(y + 1, x, cnt + 1));
        que.push(make_tuple(y - 1, x, cnt + 1));
        que.push(make_tuple(y, x + 1, cnt + 1));
        que.push(make_tuple(y, x - 1, cnt + 1));
        
    }
    
    if(dist == -1) printf("-1\n");
    else printf("%d\n", WHITE - dist - 1);
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<string>
#define lens 10000
using namespace std;

int m, n;
int a[lens],b[lens];

int find(int k)
{
	for (int i = 0; i < m; i++)
	{
		if(a[i]==k)
			return 1;
	}
	return 0;
}

int main()
{
	int sum = 0;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> a[i];
	}
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		if (find(t))
			sum++;
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

struct edge{
  int from, to;
  int weight;

  bool operator<(const edge &r) const{
    return weight != r.weight ? weight > r.weight : // !!INVERSE!!
    from != r.from ? from < r.from : to < r.to;
  }
};

class Kruskal{
  public:
  int Num; //ノードの数
  vector<int> par; //親の番号
  vector<int> height; //木の高さ(ランク)
  vector<edge> Edges;

  Kruskal(int N):
    par(vector<int>(N, 0)), height(vector<int>(N, 0)), Num(N) {}

  //初期化
  void init(){
    REP(i, Num){
      par[i] = i;
      height[i] = 0;
    }
  }

  //xの親番号を返す、再帰処理あり
  int root(int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  //xとyの親番号が同一か判定する
  bool same(int x, int y){
    return root(x) == root(y);
  }

  //xとyのある木を結合する
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return; //親が同一なら結合済み。

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

  //Kruskal法
  int operate(priority_queue<edge> &Q){
    int total_weight=0;
    while(Edges.size()<Num-1 && !Q.empty()){
      edge e = Q.top();
      Q.pop();
      if(!same(e.from, e.to)){
        unite(e.from, e.to);
        Edges.push_back(e);
        total_weight += e.weight;
      }
    }
    return total_weight;
  }
};



int main(){
  int V, E;
  cin >> V >> E;
  priority_queue<edge> que;
  Kruskal KR(V);
  int start, to, weight;
  REP(i, E){
    cin >> start >> to >> weight;
    que.push((edge){start, to, weight});
  }

  KR.init();
  cout << KR.operate(que) << endl;



  return 0;
}



Measured memory_bytes: 4680
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

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

	vector<pair<int,int>> items;
	for (int i = 0; i < N; i++){
		int v, w; cin >> v >> w;
		items.push_back(pair<int,int>(v,w));
	}
	vector<vector<int>> dp(N+1,vector<int>(W+1,0));
	for (int i=0;i<N;i++){
		for(int w=0;w<W+1;w++){
			if (w >= items[i].second) dp[i+1][w] = max(dp[i][w],dp[i][w-items[i].second] + items[i].first);
			else dp[i+1][w] = dp[i][w];
		}
	}
	cout << dp[N][W] << endl;

	
	return 0;
}




Measured memory_bytes: 6804