akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;

typedef long long ll;
const int N = 81;
const ll MOD = 1000000007;

int n,m;
int a[N][N];

bool dp[N][N][20002];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n>>m;
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			int x;
			cin>>x;
			a[i][j] -= x;
		}
	}
	
	dp[0][1][10000] = 1;
	dp[1][0][10000] = 1;
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=0;k<20000;k++){
				if(k + a[i][j] < 0 || k + a[i][j] > 20000)continue;
				if(dp[i][j-1][k]){
					dp[i][j][k+a[i][j]] = true;
				}
			}
			for(int k=0;k<20000;k++){
				if(k - a[i][j] < 0 || k - a[i][j] > 20000)continue;
				if(dp[i][j-1][k]){
					dp[i][j][k-a[i][j]] = true;
				}
			}
			for(int k=0;k<20000;k++){
				if(k + a[i][j] < 0 || k + a[i][j] > 20000)continue;
				if(dp[i-1][j][k]){
					dp[i][j][k+a[i][j]] = true;
				}
			}
			for(int k=0;k<20000;k++){
				if(k - a[i][j] < 0 || k - a[i][j] > 20000)continue;
				if(dp[i-1][j][k]){
					dp[i][j][k - a[i][j]] = true;
				}
			}
		}
	}
	int ans = -1;
	for(int i=0;i<10000;i++){
		if(dp[n][m][10000+i] || dp[n][m][10000-i]){
			ans = i;
			break;
		}
	}
	
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 103452
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};

typedef struct node * Node;

Node root,NIL;

Node treeMinimum(Node x){
  while(x -> left != NIL){
    x = x-> left;
  }
    return x;
}

Node treeMaximum(Node x){
    while(x -> right != NIL){
     x = x -> right;
    }
    return x;
}

Node treeSearch(Node u,int k){
  while(u != NIL && k != u-> key){
    if(k < u -> key) u = u-> left;
    else u = u -> right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x -> right != NIL)
  return treeMinimum(x -> right);

  Node  y = x -> p;
  while(y != NIL && x == y -> right){
    x = y;
    y = y -> p;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z -> left == NIL || z -> right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y -> left != NIL) x = y -> left;
  else x = y -> right;

  if(x != NIL) x -> p = y -> p;
  
  if(y -> p == NIL) root = x;
  else if (y == y -> p -> left) y -> p -> left = x;
  else y -> p -> right = x;
  
  if(y != z) z -> key = y -> key;

  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while(x != NIL){
    y = x;
    if(z -> key < x -> key) x = x -> left;
    else x = x -> right;
  }
  
  z -> p = y;

  if(y == NIL) root = z;
  else if (z -> key < y -> key) y -> left = z;
  else y -> right = z;
  }

void inorder(Node u){
    if(u == NIL) return;
    
    inorder(u -> left);
    printf(" %d",u -> key);
    inorder(u -> right);
}

void preorder(Node u){
    if(u == NIL) return;
    
    printf(" %d",u -> key);
    preorder(u -> left);
    preorder(u -> right);
}


int main(){
  int n, i, x;
  char com[20];
  
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } 
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20524
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N; cin >> N;
	string s; cin >> s;
	if (N % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < N/2; i++) {
		if (s[i] != s[N / 2 + i]) {
			cout << "No" << endl;
			return 0;
		}
			
	}
	cout << "Yes" << endl;







	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    
    int min = 200000;
    int count = 0;
    for (int i=0; i<n; i++) {
      int current = sc.nextInt();
      if (min>=current) {
        count ++;
        min = current;
      }
    }

    System.out.println(count);
    
  }
}

Measured memory_bytes: 63128
fun main(args: Array<String>) {
    val (n, m, c) = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }
    val am = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }

    var ans = 0
    for (list in am) {
        var v = 0
        for ((i, a) in list.withIndex()) {
            v += a * b[i]
        }
        v += c
        if (v > 0) {
            ans++
        }
    }
    println(ans)
}

Measured memory_bytes: 37816
#include <cstdio>

long long sum[43];
long long p1[43], p2[43];

void cal(long long *p, long long x) {
    for(int i = 0; i < 40; i++) {
        long long a = 1ll << i;
        long long b = 1ll << (i + 1);
        p[i] = ((x + a) / b - 1) * a;
        if(p[i] < 0) p[i] = 0;
        if((x + a) / b * b > 0) {
            if((x + a) / b * b > x) p[i] += x - ((x + a) / b * b - a) + 1;
            else p[i] += a;
        }
    }
}

int main() {
    long long n, m;
    scanf("%lld %lld", &n, &m);
    if(n > 0) n--;
    cal(p1, n);
    cal(p2, m);
    long long ans = 0;
    for(int i = 0; i < 40; i++) if((p2[i] - p1[i]) & 1) ans += 1ll << i;
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
    string s; cin >> s;
    int n = s.size();
    long long r = 0; long long b = 0;
    long long dp[2*n+1][2*n+1];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 0; i < 2*n; i++) {
        if (i < n) {
            if (s[i] == '0') {
                r += 2;
            } else if (s[i] == '1') {
                r += 1; b += 1;
            } else {
                b += 2;
            }
        }
        for (int j = 0; j < 2*n+1; j++) {
            if (j < r) {
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= mod;
            }
            if (i-j < b) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mod;
            }
        }
    }
    cout << dp[2*n][r] << endl;
    return 0;
}

Measured memory_bytes: 125312
import java.math.BigDecimal;
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        String[] aStr = sc.nextLine().split(" ");
        String[] bStr = sc.nextLine().split(" ");

        long[] a = new long[n + 1];
        long[] b = new long[n];
        for (int i = 0; i < n + 1; i++) {
            a[i] = Long.parseLong(aStr[i]);
        }

        for (int i = 0; i < n; i++) {
            b[i] = Long.parseLong(bStr[i]);
        }


        long ans = 0;

        for (int i = 0; i < n; i++) {
            if (b[i] > a[i]) {
                ans += a[i];
                b[i] -= a[i];
            } else {
                ans += b[i];
                continue;
            }

            if(b[i] > a[i + 1]){
                ans += a[i + 1];
                a[i + 1] = 0;
            } else {
                ans += b[i];
                a[i + 1] -= b[i];
            }

        }

        System.out.println(ans);
    }


}


Measured memory_bytes: 61336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mk make_pair



int main()
{
    int n,sumb=0;
    cin>>n;
    vector<int> a(n),b(n),c(n-1);
    
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>b[i];
        }
        for(int i=0;i<n-1;i++)
        {
            cin>>c[i];
        }
    
    for(int i=0;i<n;i++)
    {
        sumb+=b[i];
    }
    //cout<<sumb<<endl;
    for(int i=0;i<n-1;i++)
    {
        if(a[i+1]-a[i]==1)
        {
            //cout<<a[i]<<endl;
            sumb+=c[a[i]-1];
        }
    }
    cout<<sumb;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
map<pair<long long,long long>,long long >M;
long long f(long long A,long long B){
	if(A>B)return 0;
	long long cur=(B|A);
	long long N=B-A+1;
	for(int i=0;i<60;i++){
		if(N>(1LL<<i))cur|=(1LL<<i);
	}
	return cur;
}
bool chk(long long A,long long B,long long C){
	long long now=0;
	for(int i=0;i<60;i++){
		if(C&(1LL<<i)){
			long long tmp=C-(1LL<<i);
			if(A<=tmp&&tmp<=B){
				return true;
			}else{
				;
			}
		}
	}
//	long long need=0;
//	for(int i=0;i<60;i++)if((C-now)&(1LL<<i))need+=1LL<<i;
//	printf("%lld %lld %lld: %lld %lld\n",A,B,C,now,need);
//	if(need==0||(A<=need&&need<=B))return true;
//	else return false;
	return false;
}
long long calc(long long A,long long B){
	if(M.count(make_pair(A,B)))return M[make_pair(A,B)];
	long long ret=0;
	if(A==B)ret=1;
	else{
		ret=calc((A+1)/2,B/2);
		int ks=1;
		if(B%2==0){
			/*
			long long left=A-1;
			long long right=B;
			while(left+1<right){
				long long mid=(left+right)/2;
				long long cur=f(mid,B-1);
				if((cur|B)!=cur)right=mid;
				else left=mid;
			}
			if(right/2<=(B-1)/2)ret+=calc(right/2,(B-1)/2);
			*/
 
			if(!chk(A/2,B/2-1,B/2))ret--;
		}
		ret+=calc(A/2,B/2);
 
	}
	//printf("%lld %lld: %lld\n",A,B,ret);
	return M[make_pair(A,B)]=ret;
}
int main(){
	long long A,B;
	scanf("%lld%lld",&A,&B);
	printf("%lld\n",calc(A,B));
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t H,W;
std::string map[510];
std::string map2[510];
std::string map3[510];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H>>W;
	for (int32_t i = 0; i < H; i++)
	{
		in >> map[i];
	}
	for (int32_t i = 0; i < H; i++) {
		map2[i] = map[i];
		map3[i] = map[i];
	}

	for (int32_t i = 1; i < H-1; ++i) {
		if (i & 1)
		{
			for (auto& c : map2[i]) { c = '#'; }
			map2[i].front() = map2[i].back() = '.';
		}
		else
		{
			map2[i][W - 2] = '#';
		}
	}
	for (int32_t i = 0; i < H; ++i) {
		map3[i].front() = map3[i].back() = '#';
		if (i & 1)
		{
		}
		else
		{
			for (auto& c : map3[i]) { c = '#'; }
			if(map[i][W-2]=='.'){ map3[i][W - 2] = '.';	}
		}
	}
	for (auto& i : map3[0]) { i = '#'; }
	for (auto& i : map3[H-1]) { i = '#'; }

	for (int32_t i = 0; i < H; i++) {
		out << map2[i] << endl;
	}
	out<< endl;
	for (int32_t i = 0; i < H; i++) {
		out << map3[i] << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007
vector<int> preorder(41), inorder(41);

vector<int> getpostorder(int pl, int pr, int il, int ir)
{
	// pl??????pr-1????????????????¨????
	int root = preorder[pl];
	for(int i = 0; il + i < ir; i++){
		if(inorder[il + i] == root){
			vector<int> left = getpostorder(pl + 1, pl + i + 1, il, il + i);
			vector<int> right = getpostorder(pl + i + 1, pr, il + i + 1, ir);
			copy(right.begin(), right.end(), back_inserter(left));
			left.push_back(root);
			return left;
		}
	}
	return vector<int>();
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> preorder[i];
	}
	for(int i = 0; i < n; i++){
		cin >> inorder[i];
	}
	vector<int> postorder = getpostorder(0, n, 0, n);
	for(int i = 0; i < n; i++){
		cout << postorder[i];
		if(i == n - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 3164
'use strict'
const main = (input) => {
  input = input.split('\n')[0].split('');
  const s = "";
  
  for (const i = 0; i<input.length; i++) {
    if (input[i]=="0") {
      s += "0";
    }else if(input[i]=="1"){
      s += "1"
    }else{
      s = s.slice(0, -1);
    }
  }
  console.log(s);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,tmp=0,tmp2=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%s",s);
  n = strlen(s);
  for(i=0;i<(1<<(n-1));i++){
    tmp=(s[0]-'0');
    tmp2=0;
    for(j=0;j<n-1;j++){
      if(i & (1<<j)){
        tmp2+=tmp;
        tmp = (s[j+1]-'0');
      }else{
        tmp*=10;
        tmp += (s[j+1]-'0');
      }
    }
    tmp2+=tmp;
    result += tmp2;
  }
  printf("%lld\n",result);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a - b * 2 < 0 ? 0 : a - b * 2);
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
int n, m;

int main(){
	IOS
	vector<int>arr;
	cin >> n >> m;
	while(n--){
		arr.push_back(2);
	}
	while(m--){
		arr.push_back(1);
	}
	ll ans=0;
	for(int i=0;i<arr.size();i++){
		for(int j=i+1;j<arr.size();j++){
			if((arr[i]+arr[j])%2==0){
				ans++;
			}
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3616
N, Y = map(int, input().split())

n1000 = Y % 5000 // 1000
n5000 = N - n1000
n10000 = 0

while True:
    tot = n10000 * 10000 + n5000 * 5000 + n1000 * 1000
    if tot == Y:
        print(n10000, n5000, n1000)
        break

    if n5000 <= 0:
        print(-1, -1, -1)
        break

    if tot > Y:
        n5000 -= 5
        n1000 += 5
    else:
        n5000 -= 1
        n10000 += 1


Measured memory_bytes: 3060
N,W = [int(x) for x in input().split()]
dp = [[0]*(W+1) for _ in range(N+2)]
uv = [[0,0]]+[[int(x) for x in input().split()] for _ in range(N)]
for i in range(N+1):
  for j in range(W+1):
    dp[i+1][j] = max(dp[i+1][j],dp[i][j])
    if uv[i][0]+j<=W:
      dp[i+1][j+uv[i][0]] = max(dp[i][j]+uv[i][1],dp[i+1][j+uv[i][0]])
print(max(dp[N+1]))

Measured memory_bytes: 121196
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505


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

	ll n;
	ll a[5], k = 125;
	cin >> n;
	ll min = 1e18, in = 0;
	for (int i = 0; i < 5; ++i)
	{
		cin >> a[i];
		if(a[i] <= min)
		{
			min = a[i];
			in = i;
		}
	}
	ll ans = in;
	ans += n/ min + (n % min ? 1 : 0);
	ans += 4 - in;
	cout << ans << "\n";
	return 0;
}

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

int main(void){
    
    char a[10]={},b[10]={},c[10]={};
    int len_a,len_b;
    
    scanf("%s %s %s",a,b,c);
    
    len_a = strlen(a)-1;
    len_b = strlen(b)-1;
    
    if(a[len_a]==b[0]&&b[len_b]==c[0])printf("YES");
    else printf("NO");
    
    return 0;
}

Measured memory_bytes: 128
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int nowx=0,nowy=0;
    int last_t=0;
    int i;
    for (i=0;i<n;i++)
    {
        int t,x,y;
        scanf("%d%d%d",&t,&x,&y);
        int sum=abs(x-nowx)+abs(y-nowy);
        if ((sum>t-last_t)||(sum%2!=(t-last_t)%2))
        {
            puts("No");
            return 0;
        }
        nowx=x;
        nowy=y;
        last_t=t;
    }
    puts("Yes");
    return 0;
} 


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
    }
    fn ketasu(n: usize) -> usize {
        let mut i = 0;
        let mut n = n;
        while n != 0 {
            n /= 10;
            i += 1;
        }
        i
    }
    let mut count = 0;
    for i in 1..n + 1 {
        if ketasu(i) % 2 == 1 {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
//
//AtCoder Beginner Contest 170
//C - Forbidden List
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> flags(102, 0);
    REP(i, n) {
        int p;
        cin >> p;
        flags[p]=1;
    }
    pair<int, int> pmin(9999999, -1);
    FOR(i, 0, 101){
        if (flags[i]==1) continue;
        pair<int, int> ptmp(abs(x-i), i);
        pmin = min(pmin, ptmp);
    }
    cout << pmin.second << endl;
    return 0;
}


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.8lf", sqrt(d));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int six, nine, ans = N, count;
  for(int i = 0; i <= N; i++) {
    six = i;
    nine = N - i;
    count = 0;
    while(six != 0){
      count += six % 6;
      six /= 6;
    }
    while(nine != 0){
      count += nine % 9;
      nine /= 9;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli=long long;
int main(){
  lli n;
  cin >> n;
  vector<lli> vec(n), arr(n);
  for(int i=0;i<n;i++){
    cin >> vec[i];
    arr[i] = vec[i] + i+1;
  }
  sort(arr.begin(), arr.end());
  lli ans = 0;
  for(int i=0;i<n;i++){
    ans+=distance(
      lower_bound(arr.begin(), arr.end(), i+1 - vec[i]),
      lower_bound(arr.begin(), arr.end(), i+2 - vec[i])
    ) ;
  }
  cout << ans;
}

Measured memory_bytes: 6432
N,M,C = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
for _ in range(N):
    A = list(map(int, input().split()))
    val = 0;
    for i in range(M):
        val += A[i] * B[i]
    val += C
    if val > 0:
        count += 1

print(count)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MOD 1000000007
#define MAXN 500006
using namespace std;
const int p=131;
bool l[MAXN],r[MAXN];
long long hash[MAXN],bitp[MAXN];
int n,ans;
char s[MAXN];
long long Hash(int l,int r)
{
	return ((hash[r]-hash[l-1]*bitp[r-l+1]%MOD)%MOD+MOD)%MOD;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	hash[0]=0;
	bitp[0]=1;
	for(int i=1;i<=n;i++)
	{
		hash[i]=(hash[i-1]*p+s[i])%MOD;
		bitp[i]=bitp[i-1]*p%MOD;
	}
	for(int d=1;d<=n;d++)
		for(int i=d+d;i<=n;i+=d)
			if(Hash(1,i-d)==Hash(d+1,i)) l[i]=1;
	for(int d=1;d<=n;d++)
		for(int i=n-d*2+1;i>=1;i-=d)
			if(Hash(i,n-d)==Hash(i+d,n)) r[i]=1;
	if(r[1]==0) 
	{
		printf("1\n1");
		return 0;
	}
	for(int i=1;i<n;i++)
		if(!l[i]&&!r[i+1]) ans++;
	if(ans==0) printf("%d\n1",n);
	else printf("2\n%d",ans);
}

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

int main(){
    long long A,B,C,D;
    cin >> A >> B >> C >> D;
    long long r;
    long long M = C;
    long long N = D;
    
    if (M < N){
        long long x = M;
        M = N;
        N = x;
    }
    while (N != 0){
        r = N;
        N = M % N;
        M = r;
    }
    long long gcd = M;
    long long lcm = C * D /gcd;
    long long count_B = B - B/C - B/D + B/lcm;
    long long count_A = (A-1) - (A-1)/C - (A-1)/D + (A-1)/lcm;
    cout << count_B - count_A << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll N;
    cin >> N;
    vel a(N);
    ll X = 0, Y = 0;
    rep(i, N) {
        cin >> a[i];
        X += a[i];
    }
    ll ans = 1000000000000000000LL;
    rep(i, N) {
        Y += a[i];
        if (i < N - 1) {
            ans = min(ans, abs(X - 2 * Y));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3

s = list(str(input()))
N = len(s)


def disc(s):
    s1 = s
    s2 = s[:]
    s2.reverse()
    if s1 == s2:
        return True
    else:
        return False


if disc(s) and disc(s[:(N-1)//2]) and disc(s[(N+3)//2-1:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);

    void solve() {
        int N = sc.nextInt();
        int ans = 0;
        int minV = 1000;
        for (int i = 0; i < N; i++) {
            int s = sc.nextInt();
            ans += s;
            if (s % 10 != 0) minV = Math.min(minV, s);
        }
        if (minV != 1000 && ans % 10 == 0) {
            ans -= minV;
        }
        if (ans % 10 == 0) System.out.println(0);
        else System.out.println(ans);
    }
}

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

const int MOD = (int) 1e9 + 7;
const int N = (int) 1e5;
int x[N];

int main() {
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for (int i = 0; i < n; ++i) cin >> x[i];
	int cnt = 0;
	long long res = 1;
	for (int i = 0; i < n; ++i) {
		++cnt;
		if (x[i] < 2 * cnt - 1) {
			res = res * cnt % MOD;
			--cnt;
		}
	}
	for (int i = 1; i <= cnt; ++i) res = res * i % MOD;
	cout << res << endl;
	return 0;
}


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

int main(){

    int n , k;
    int r, s, p;
    cin >> n >> k;
    cin >> r >> s >> p;
    char T[n + 1 + k];
    cin >> T;

    int i, ans;
    ans = 0;
    for(i = 0; i <= n ; i++){
        if(i - k + 1 > 0 and T[i] == T[i-k]){

            if(T[i] == T[i+k] and T[i+k] == 'r') T[i] = 's';
            else if(T[i] == T[i+k] and T[i+k] == 's') T[i] = 'p';
            else if(T[i] == T[i+k]  and T[i+k] == 'p') T[i] = 'r';

        }
         else{
            if(T[i] == 'r') ans = ans + p;
            else if(T[i] == 's') ans = ans + r;
            else if(T[i] == 'p') ans = ans + s;
         }   
    
    }

    cout << ans << endl;

}

Measured memory_bytes: 384
// Gaurav Nuti
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define ar array
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define INF 1e9 

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

ll power_without_mod(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1;
        x = (x*x); 
    } 
    return res; 
}

bool comparep(pair<ll, ll> i1, pair<ll, ll> i2){
	return (i1.S < i2.S);
} 

ll modInverse(ll a)
{
    return power(a , mod - 2);
}

// vector< vector<ll>> graph;
// vector<bool> visited;
// vector<ar<ll,2>> dp;

// void bfs(int u){
//     queue<ll> q;
//     q.push(u);
//     visited[u] = 1;
//     while(!q.empty()){
//         int u1 = q.front();
//         q.pop();
//         for(auto i = graph[u1].begin();i!=graph[u1].end();i++){
//             num[*i]--;
//             dist[*i] = max(dist[u1] + 1,dist[*i]);
//             if(!visited[*i] && num[*i] == 0){
//                 visited[*i] = 1;
//                 q.push(*i);
//             }
//         }
//     }
// }

// void dfs(ll u){
//     visited[u] = true;
//     if(graph[u].size() == 0){
//         dp[u][0] = 1;
//         dp[u][1] = 1;
//         return;
//     }

//     dp[u][0] = 1;
//     dp[u][1] = 1;
//     for(auto i = graph[u].begin();i!=graph[u].end();i++){
//         if(!visited[*i]){
//             dfs(*i);
//             dp[u][0] *= (dp[*i][0] + dp[*i][1]);
//             dp[u][0] %= mod;
//             dp[u][1] *= (dp[*i][0]);
//             dp[u][1] %= mod;
//         }
//     }
// }

// int next_lunlun(ll n){
//     vector<int> digits;
//     while(n){
//         digits.pb(n%10);
//         n /= 10;
//     }
//     // reverse(digits.begin(),digits.end());
//     ll num_digits = digits.size(); 
//     int count_9 = 0;
//     for(int i: digits)
//         if(i == 9)
//             count_9++;
//     if(count_9 == num_digits)
//         return ;
//     for(int i=0;i<(num_digits-1);i++){
//         if(digits)
//     }
// }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
	
    ll t;
    // cin>>t;
    t = 1;
    for(ll z=0;z<t;z++){
        ll a;
        cin>>a;
        cout<<a + a*a + a*a*a;
    }
}

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

using namespace std;

int main()
{
    string S;
    cin>>S;
    if(S[0]=='A')
    {
        int x=0, a=-1, c=0;

        for(int i=2; i<S.length()-1; i++)
        {
            if(S[i]=='C')
            {
                x++;
                a=i;
            }
        }
        if(x==1)
        {
            for(int i=1; i<S.length(); i++)
            {
                if(i==a)
                {
                    continue;
                }
                if(S[i]<='Z')
                {
                    c=1;
                }
            }
            if(c==0)
            {
                cout<<"AC"<<endl;
                return 0;
            }
        }
    }
    cout<<"WA"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    int count = 0;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        if(p[i] != i + 1){
            count++;
        }
    }
    if(count <= 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define req(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define qer(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main(){
    int n;cin>>n;
    cout<<(powmod(10,n)-powmod(9,n)*2+powmod(8,n)+mod*2)%mod;
    return 0;
}

Measured memory_bytes: 3600
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL n,a[100000+1];
LL res=0;
const int MOD=1e9+7;
LL my_pow(LL A,LL B){
	if(!B) return 1;
	LL tmp=my_pow(A,B>>1);
	tmp*=tmp;
	tmp%=MOD;
	if(B&1){
		tmp*=A;
		tmp%=MOD;
	}
	return tmp;
}
LL div_(LL A,LL B){
	return A*my_pow(B,MOD-2);
}
int main(){
	fastio;
	 cin>>n;
	 rb(i,1,n)
	 	cin>>a[i];
	int A,B;
	A=1;
	B=n;
	LL sum=0;
	rb(i,1,n){
		sum+=div_(1,i);
		sum%=MOD;
	}
	rb(i,1,n){
		if(i!=1){
			sum+=div_(1,++A);
			sum-=div_(1,B--);
			sum+=MOD;
			sum%=MOD;
		}
		res+=a[i]*sum,res%=MOD; 
	}
	rb(i,1,n)
	{
		res*=i,res%=MOD;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int MAX = 2000;

int d[110], p[110];
int color[110];

int main() {
  int n;
  std::cin >> n;
  int G[110][110];

  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) {
      int v;
      std::cin >> v;
      if(v != -1) {
        G[i][j] = v;
      } else {
        G[i][j] = MAX;
      }
    }
  }

  for(int i=0; i<n; ++i) {
    color[i] = WHITE;
    d[i] = MAX;
  }

  d[0] = 0;
  p[0] = 0;

  while(true) {
    int mini_cost = MAX;
    int u;
    // 最小の重みとなる辺を探している
    for(int i=0; i<n; ++i) {
      if(color[i] != BLACK && d[i] < mini_cost) {
        mini_cost = d[i];
        u = i;
      }
    }

    if(mini_cost == MAX) {
      break;
    }

    color[u] = BLACK;

    for(int v=0; v < n; ++v) {
      if(color[v] != BLACK && G[u][v] != MAX) {
        if(G[u][v] < d[v]) {
          d[v] = G[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }

  int d_sum = 0;
  for(int i=0; i<n; ++i) {
    d_sum += d[i];
  } 

  std::cout << d_sum << std::endl;
}


Measured memory_bytes: 3116
def changeBoard(board, i, j, d):
    n = 8
    for k in range(n):
        board[i][k] += d
        board[k][j] += d
    if i > j:
        for k in range(n - i + j):
            board[k + i - j][k] += d
    else:
        for k in range(n - j + i):
            board[k][k + j - i] += d
    if i + j < n:
        for k in range(i + j):
            board[i + j -k][k] += d
    else:
        for k in range(i + j - n + 1, n):
            board[i + j -k][k] += d

def checkQueen(queen, initial):
    for r in initial.keys():
        if queen[r] != initial[r]:
            return False
    return True

def printQueen(queen):
    for c in queen:
        line = list("........")
        line[c] = "Q"
        print("".join(line))

def setQueen(queen, board, i, initial):
    n = 8
    if i == n:
        if checkQueen(queen, initial):
            printQueen(queen)
        return
    for j in range(n):
        if board[i][j] == 0:
            queen[i] = j
            changeBoard(board, i, j, 1)
            setQueen(queen, board, i + 1, initial)
            changeBoard(board, i, j, -1)

b = [[0 for i in range(8)] for j in range(8)]
q = [-1 for i in range(8)]
q_ini = {}

k = int(input())
for i in range(k):
    r, c = map(int, input().split())
    q[r] = c
    q_ini[r] = c

setQueen(q, b, 0, q_ini)

Measured memory_bytes: 5612
N = int(input())
alph = list("abcdefghij")
ans = []

if N == 1: print("a")
def roop(root,use):
    if len(root) != N:
        for i in range(use+1):
            ans = root + alph[i]
            roop(ans,max(i+1,use))
            if len(ans) == N:
                print(ans)

roop("a",1)

Measured memory_bytes: 4340
/*
author : shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,k,i,diff;
    cin>>a>>b>>k;
    map<ll,ll>m;
    m[a]+=1;
    m[b]+=1;
    diff=b-a+1;
    if(k>=diff)
    {
        for(i=a;i<=b;i++)
            cout<<i<<endl;
    }
    else
    {
        m[k+a]+=1;
        m[b-k]+=1;
        if((a+k-1)>=(b-k+1))
            for(i=a;i<=b;i++)
                cout<<i<<endl;
        else
        {
            for(i=a;i<(a+k);i++)
                cout<<i<<endl;
            for(i=(b-k+1);i<=b;i++)
                cout<<i<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
const int MAXN = 2e5 + 5, MAXM = 2e3 + 5, BOUND = 2e5, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-3;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define lc(x) ch[x][0]
#define pii pair<int,int>
#define rc(x) ch[x][1]
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n;
vector<int> a, ans;
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	a.resize(n);;
	rep(i, 0, n - 1)cin >> a[i];
	rep(k, 1, n) {
		bool flag = false;
		for (int i = (int)a.size() - 1; ~i; i--) {
			if (a[i] == i + 1) {
				ans.push_back(a[i]);
				a.erase(a.begin() + i);
				flag = true;
				break;
			}
		}
		if (!flag)return cout << "-1\n", 0;
	}
	for (int i = (int)ans.size() - 1;~i ; i--)cout << ans[i] << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<long long> h(n);
    for( int i=0; i<n; i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    long long sum;
    sum =0;
    for( int i=0; i<n-k; i++){
        sum = sum + h[i];
    }
    cout << sum << endl;
}




Measured memory_bytes: 1792
N,x=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i).sort
ans = 0
tmp = 0
0.upto(N-1) do |i|
    tmp += a[i]
    if tmp == x
        ans = i + 1
        break
    end
    if tmp > x
        break
    end
    ans = i + 1
end

if tmp < x
    puts ans - 1
else
    puts ans
end



Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

#include <regex>
#include <locale>
#include <iomanip>

using namespace std;
using ll = long long;

#define OVERLOAD3(_1,_2,_3,name,...) name
#define REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a),i##_Len=int(b);i<i##_Len;++i)
#define rep(...) OVERLOAD3(__VA_ARGS__,REPI,REP,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int n, m;
  cin >> n >> m;
  cout << n*n - m << endl;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(void) {
    io;
    int a,b; cin >> a >> b;
    char achar = '0' + a, bchar = '0' + b;
    string astr, bstr;
    rep(i, a) bstr.push_back(bchar);
    rep(i, b) astr.push_back(achar);
    cout << ((astr < bstr) ? astr : bstr);
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 666666666

/*
    Convex Hull Trick LiChao
    !important maxn should be set to maximum possible x value
    its a kind of segment tree that supports 2 operations:
    1) add line y=a*x+b to the tree by calling add_line({a,b});
    2) get minimum value for some y given x
    (untested)*3) if we want maximum value we just add line as {-a,-b}
*/
typedef ll ftype;
typedef complex<ftype> point;

ftype dot(point a, point b) {
    return (conj(a) * b).real();
}

ftype f(point a,  ftype x) {
    return dot(a, {x, 1});
}

const int maxn = 1e6+5;

point line[4 * maxn];

void add_line(point nw, int v = 1, int l = 0, int r = maxn) {
    int m = (l + r) / 2;
    bool lef = f(nw, l) < f(line[v], l);
    bool mid = f(nw, m) < f(line[v], m);
    if(mid) {
        swap(line[v], nw);
    }
    if(r - l == 1) {
        return;
    } else if(lef != mid) {
        add_line(nw, 2 * v, l, m);
    } else {
        add_line(nw, 2 * v + 1, m, r);
    }
}

ll Get(ll x, int v = 1, int l = 0, int r = maxn) {
    ll m = (l + r) / 2;
    if(r - l == 1) return f(line[v], x);
    if(x < m)return min(f(line[v], x), Get(x, 2 * v, l, m));
    return min(f(line[v], x), Get(x, 2 * v + 1, m, r));
}

ll H[maxn];
ll DP[maxn];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,C;
    cin>>n>>C;
    for(int i=1; i<=n; i++)
        cin>>H[i];

    //(H[i]-H[j])^2 + C = H[i]^2 -2*H[i]*H[j] + H[j]^2 + C
    //DP[i] = min(H[i]^2 -2*H[i]*H[j] + H[j]^2 + DP[j]) for all j
    // we notice that f(H[j]) = (-2*H[i])*H[j] + (H[j]^2+DP[i])
    // we notice that f(x) = (-2*H[i])*x + (H[j]^2+DP[i])

    add_line({-2*H[1],H[1]*H[1]});

    for(int i=2; i<=n; i++)
    {
        DP[i]=H[i]*H[i] + Get(H[i]) + C;
        add_line({-2*H[i],H[i]*H[i]+DP[i]});
    }
    cout<<DP[n];
}


Measured memory_bytes: 40704
def partition(a)
  x = a.last
  r = a.size
  i = 0
  i.upto(r - 1) do |j|
    if a[j] <= x
      a[i], a[j] = a[j], a[i]
      i += 1
    end
  end
  a[0..i-2].join(' ') + " [#{a[i-1]}] " + a[i..-1].join(' ')
end

n = gets.to_i
a = gets.chomp.split.map(&:to_i)
puts partition(a)

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

using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define repp(i, a, b) for (long long i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> A(n + 1);
    rep(i, 0, n)
    {
        cin >> A[i].first >> A[i].second;
    }
    vector<vector<long long>> dp(n + 1, vector<long long>(100010, 1000000000000));
    dp[0][0] = 0;
    for (long long i = 0; i < n; i++)
    {
        for (long long j = 0; j < 100010; j++)
        {
            if (A[i].second <= j)
            {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - A[i].second] + A[i].first);
            }
            else
            {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    long long ans = 0;
    rep(i, 0, 100010)
    {
        if (dp[n][i] <= m)
        {
            ans = max(ans, i);
        }
    }
    cout << ans;
}


Measured memory_bytes: 80256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

const int MAX = 2e5 + 1;

int dpl[MAX];
int dpr[MAX];

int dpl2[MAX];
int dpr2[MAX];

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

	int N, K, C;
	cin >> N >> K >> C;

	string str;
	cin >> str;

	dpl[0] = 0;
	int last_l = -1e6;
	for (int i = 1; i <= N; i++)
	{
		if (str[i - 1] == 'o' && last_l + C < i)
		{
			last_l = i;
			dpl[i] = dpl[i - 1] + 1;
		}
		else
		{
			dpl[i] = dpl[i - 1];
		}
	}

	dpr[N] = 0;
	int last_r = 1e6;
	for (int i = N; i >= 1; i--)
	{
		if (str[i - 1] == 'o' && last_r - C > i)
		{
			last_r = i;
			dpr[i - 1] = dpr[i] + 1;
		}
		else
		{
			dpr[i - 1] = dpr[i];
		}
	}

	for (int i = 0; i < N; i++)
	{
		if (str[i] == 'o' && dpl[i] + dpr[i + 1] == K - 1)
		{
			cout << i + 1 << "\n";
		}
	}

	return 0;
}


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

int main(){
  double a,b,c,s,l,h;
  static const double pi = 3.141592653589793;
  cin>>a>>b>>c;
  double rad = c/360*2*pi;
  h=b*sin(rad);
  s=a*h*1/2;
  l=sqrt(a*a+b*b-2*a*b*cos(rad)) + a + b;

  printf("%.10lf ",s);
  printf("%.10lf ",l);
  printf("%.10lf",h);

  return 0;
}

Measured memory_bytes: 3508
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	if(a==1||b==1){
		if(a==1&&b==1)puts("Draw");
		else puts(a==1?"Alice":"Bob");
	}else{
		puts(a==b?"Draw":a>b?"Alice":"Bob");
	}
}

Measured memory_bytes: 128
import sys
K = int(input())

if K%2 == 0 or K%5 == 0:
    print(-1)
    sys.exit()

dp = 7
ans = 1

while(ans <= 10000000):
    if dp % K == 0:
        print(ans)
        sys.exit()
    ans += 1
    dp = (dp * 10 + 7) % K

Measured memory_bytes: 9176
#![allow(dead_code)]
use crate::scanner::Scanner;
use std::cmp::min;
fn main() {
    let mut scan = Scanner::new();
    let a = scan.read::<i64>();
    let b = scan.read::<i64>();
    let n = scan.read::<i64>();
    let x = min(b - 1, n);
    println!("{}", a * x / b);
}
mod scanner {
    use std::io::{stdin, BufReader, Bytes, Read, Stdin};
    use std::str::FromStr;
    pub struct Scanner {
        buf: Bytes<BufReader<Stdin>>,
    }
    impl Scanner {
        pub fn new() -> Scanner {
            Scanner {
                buf: BufReader::new(stdin()).bytes(),
            }
        }
        pub fn read_next<T: FromStr>(&mut self) -> Option<T> {
            let token = self
                .buf
                .by_ref()
                .map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();
            token.parse::<T>().ok()
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_next().unwrap()
        }
        pub fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read::<T>()).collect()
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
    }
}



Measured memory_bytes: 2136