akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main(){
	char a[169], b[169], c[169];
	int la, lb, lc;
	scanf("%s %s %s", &a, &b, &c);
	la = strlen(a);
	lb = strlen(b);
	lc= strlen(c);
	
	if(a[la-1] == b[0] && b[lb-1] == c[0]){
		printf("YES\n");
	}
	
	else{
		printf("NO\n");
	}
	
	return 0;
	
	
}

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

int n;

int main() {
  cin >> n;
  int p[n];
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }

  int min_i = INT_MAX;
  int count = 0;

  for (int i = 0; i < n; ++i) {
    if (p[i] < min_i) {
      ++count;
    }
    min_i = min(min_i, p[i]);
  }

  cout << count << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	rep(i, 26){
		int x = i * 4;
		if((n - x) >= 0 && (n - x) % 7 == 0){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌ */
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
#include <cstring>
#include <ctime>

#define pb push_back
#define re return
#define fi first
#define se second
#define ll long long

using namespace std;





int main()
{
    int n;
    cin >> n;
    int ans=0, mn;
    cin >> mn;
    for(int i=1; i<n; i++){
        int x;
        cin >> x;
        if(x<=mn){
            mn = x;
            ans++;
        }
    }
    cout << ans+1;


}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*2
#define REP(i,n) for(long long i = 0;i < n;++i)
#define cycle_per_sec 2806192512
int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"


int main(void) {
  int A[3][3];
  int aa[3];
  int bb[3];
  int num, i, j;
  int yflg=0;
  for(i=0; i < 3; i++)
  {
      for(j=0; j < 3; j++)
      {
        if( scanf("%d", &A[i][j]) == 1);
      }
  }
  
  num = 0;
  for(num=0; num <= 100; num++)
  {
    aa[0] = num;
    bb[0] = A[0][0] - aa[0];
    if (bb[0] >= 0)
    {
      aa[1] = A[1][0] - bb[0];
      if (aa[1]>=0)
      {
        bb[1] = A[1][1] - aa[1];
        if (bb[1]>=0)
        {
          aa[2] = A[2][1] - bb[1];
          if(aa[2] >= 0)
          {
            bb[2] = A[2][2] - aa[2];
            if(bb[2] >= 0)
            {
              yflg = 1;
              for(i=0; i < 3; i++)
              {
                for(j=0; j < 3; j++)
                {
                  if(aa[i] + bb[j] != A[i][j])
                  {
                    yflg = 0;
                  }
                }
                
              }
              
            }
          }
        }
      }
    }
    
  }
  
  if (yflg == 1)
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }

  return 0;
}



Measured memory_bytes: 128
def main():
    buf = input()
    N = int(buf)
    BA = []
    for i in range(N):
        buf = input()
        buflist = buf.split()
        BA.append((int(buflist[1]), int(buflist[0])))
    BA.sort()
    elapsed = 0
    for x in BA:
        elapsed += x[1]
        if elapsed > x[0]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 29464
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int req1(int st,double b,double c,int y,bool f){
    int rsum=0;
    int u=0;

    for(int i=0;i<y;i++){
        int bb=st*b;
        if(!f){
            rsum+=bb;
            st-=c;
        }else {
            st = st + bb - c;
        }

    }
    if(!f){
        st+=rsum;
    }
    return st;



}


int main() {

    int n;
    cin >> n;
   rep(nn,n){

        if(n==0)break;
        int st,y,x;
        cin>>st>>y>>x;
        vector<int> money(x);
        rep(i,x){
            bool a;
            double b,c;
            cin>>a>>b>>c;
                money[i]=req1(st,b,c,y,a);

        }
        sort(money.rbegin(),money.rend());
        cout<<money[0]<<endl;


    }


    return 0;
}



Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	}
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string s;
  cin >> s;
  if(s[s.length() - 1] == '1' || s[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if(s.length() > 2 && s[s.length() - 2] == '0') {
    cout << -1 << endl;
    return 0;
  }
  rep(i, 0, s.length() / 2) {
    if(s[i] == '1') {
      if(s[s.length() - 2 - i] != '1') {
        cout << -1 << endl;
        return 0;
      }
    }else if(s[i] == '0') {
      if(s[s.length() - 2 - i] != '0') {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int nx = 1;
  rep(i, 1, s.length()) {
    cout << nx << " " << i + 1 << endl;
    if(s[i - 1] == '1') nx = i + 1;
  }
}


Measured memory_bytes: 1616
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0;i<(n);i++)

using ll = long long;

int N;
ll A[200005];
 
int main() {
  
  cin>>N;
  rep(i, N) {
    cin>>A[i];
    A[i] -= i+1;
  }
  
  sort(A, A+N);
  
  ll b = A[N/2];
  
  ll ans = 0;
  rep(i, N)ans += abs(A[i]-b);
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 1792
import sys
s=input()
t=input()
u=s[::-1]
v=t[::-1]
for i in range(len(u)-len(v)+1):
  count=0
  outp=u[0:i]
  for j in range(len(v)):
    w=v[j]
    x=u[i+j]
    if(w==x or x=="?"):
      outp+=w
      count+=1
    if(count==len(v)):
      print(((outp+u[i+len(v):])[::-1]).replace("?","a"))
      sys.exit()
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a),end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

double dist(double x1, double y1, double x2, double y2){
    return sqrt( ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)) );
}

double triangleArea(double x, double y, double z){
    return (y * z * sin( acos( (y * y +  z * z - x * x) / (2 * y * z) ) )) / 2;
}

double inputXY(double x1, double y1, double x2, double y2, double x3, double y3){
    double x, y ,z;
    x = dist(x1, y1, x2, y2);
    y = dist(x2, y2, x3, y3);
    z = dist(x3, y3, x1, y1);
    return triangleArea(x, y, z);
}

int main(){
    double x1, y1, x2, y2, x3, y3, xp, yp;
    double allArea, area12, area23, area31;
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
        allArea = inputXY(x1, y1, x2, y2, x3, y3);
        area12 = inputXY(xp, yp, x2, y2, x1, y1);
        area23 = inputXY(x2, y2, x3, y3, xp, yp);
        area31 = inputXY(x3, y3, x1, y1, xp, yp);

        if(abs(allArea - (area12 + area23 + area31)) < 0.000001) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 1280
# input
N, A, B, C = map(int, input().split())
S = [input() for _ in range(N)]

# process
V = {"A":A, "B":B, "C":C}
S.append("XX")
op = ""
for i in range(N):
    s0, s1 = S[i]
    if V[s0] + V[s1] == 0:
        break
    
    x, y = s0, s1
    if V[s1] == 0 or (V[s0] != 0 and s1 in S[i+1]):
        x, y = s1, s0

    V[x] += 1
    V[y] -= 1
    op += x

# output
if len(op) != N:
    print("No")
else:
    print("Yes")
    [print(x) for x in op]


Measured memory_bytes: 17200
#include <stdio.h>
int main(){
  int A,B,C,K,S=0;
  scanf("%d %d %d %d",&A,&B,&C,&K);
  if(K<=A) S=K;
  else if(K<=A+B) S=A;
  else S=A-(K-A-B);
  printf("%d\n",S);
  return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef double ld;
typedef vector<vector<ll> > mat;

const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 302;
const int M = 110;

ld d[N * 3][N * 3 / 2][N];
int cnt[N];
int a[N * 2];

void solve() {
    int n;
    cin >> n;
    fr(i, n) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    ld k = n;
    int ssum = accumulate(a, a + n, 0);
    d[0][0][0] = 0;
    for (int sum = 1; sum <= ssum; sum++)
        for (int c1 = 0; c1 <= sum; c1++)
            for (int c2 = 0; 2 * c2 <= sum; c2++) {
                int c3 = (sum - c1 - 2 * c2) / 3;
                if (c3 < 0 || (sum - c1 - 2 * c2) % 3) continue;
                d[c1][c2][c3] = ((c1 ? (c1 / k) * d[c1 - 1][c2][c3] : 0) +
                                (c2 ? (c2 / k) * d[c1 + 1][c2 - 1][c3] : 0) +
                                (c3 ? (c3 / k) * d[c1][c2 + 1][c3 - 1] : 0) + 1) / (c1 + c2 + c3) * (ld)(n);

            }
    cout << fixed << setprecision(12) << d[cnt[1]][cnt[2]][cnt[3]];
}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define sec second
#define fori(i, a, b) for(int i = int(a); i < int(b); i++)
#define cc(x)	cout << #x << " = " << x << endl
#define ok		cout << "ok" << endl

typedef pair<int,int> ii;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const long long N = 1e5 + 10; 
long long n, cost[N];
long long dp[N];

long long pog(long long at, long long n){
	if(at >= n) return 0;
	
  	long long &r = dp[at];
  	if(r != -1) return r;

	long long L = pog(at+1, n) + abs(cost[at+1]-cost[at]);
	long long R = pog(at+2, n) + abs(cost[at+2]-cost[at]);

	return r = min(L, R);
}

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

	memset(dp, -1, sizeof dp);
	cin >>n;

	for(int i = 0; i < n; i++)
		cin >>cost[i];
	
	cost[n] = INF;
	cout <<pog(0, n-1) <<endl;
	return 0;
}


Measured memory_bytes: 6528
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, B, C := sc.nextInt(), sc.nextInt(), sc.nextInt()

	if A <= C && C <= B {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
	wtr.Flush()
}


Measured memory_bytes: 640
#include<cstdio>
using namespace std;
int main(void)
{
	int n,m,a[1000],b,i,MIN,sum,nm;
	scanf("%d %d",&n,&m);
	MIN=1001;
	for(i=0;i<m;i++){
		scanf("%d %d",&a[i],&b);
		if(MIN>a[i]){
			nm=i;
			MIN=a[i];
		}
	}
	a[nm]=n;
	sum=0;
	for(i=0;i<m;i++){
		if(a[i]<n){
			sum+=n-a[i];
		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 2712
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_num(LL n) { int ret = 0; while (n > 0) { ret ++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int dp[101010];
vector<int> bank;

int main() {
	cin >> n;
	int cnt = 0;
	while (pow(6, cnt) <= n) {
		bank.emplace_back(pow(6, cnt));
		cnt++;
	}
	cnt = 0;
	while (pow(9, cnt) <= n) {
		bank.emplace_back(pow(9, cnt));
		cnt++;
	}
	bank.emplace_back(1);
	sort(ALL(bank));
	REP(i, 101010)dp[i] = INF;
	dp[0] = 0;
	REP(i,bank.size()) {
		for (int j = bank[i]; j <= n; j++) {
			dp[j] = min(dp[j], dp[j - bank[i]] + 1);
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());

int main()
{
    string a, b;
    int num;
    cin >> a >> b;
    num = stoi(a) * pow(10, b.size()) + stoi(b);
    int i = 0;
    while (i * i <= num)
    {
        if (i * i == num)
        {
            cout << "Yes" << endl;
            return 0;
        }
        i++;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>

#define llint long long int 

int main(void){
  llint W, H;
  std::cin >> W >> H;
  llint p[W], q[H];

  llint total = 0;

  for(int w=0; w<W; w++){
    std::cin >> p[w];
  }
  for(int h=0; h<H; h++){
    std::cin >> q[h];
  }


  std::sort(p,p+W);
  std::sort(q,q+H);

  int a = 0;
  int b = 0;

  while(a != W || b != H){
    if(a==W){
      total += (W-a+1)*q[b];
      b++;
    }else if(b==H){
      total += (H-b+1)*p[a];
      a++;
    }else if(p[a] < q[b]){
      total += (H-b+1)*p[a];
      a++;
    }else{
      total += (W-a+1)*q[b];
      b++;
    }
  }

  std::cout << total << std::endl;
  return 0;


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,cnt=1;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)
    cin>>a[i];
  sort(a.begin(),a.end());
  for(int i=0;i<N-1;i++){
    if(a[i]<a[i+1]){
      cnt+=1;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>
#include<iostream>

using namespace std;
int main(){
    char str[201];
    char temp[201];
    int len_str=0;
    while(1){
        scanf("%s",str);
        if(str[0]=='-')break;
        len_str=strlen(str);
        int m;
        scanf("%d",&m);
        int h[100];
        for(int i=0;i<m;i++){
            scanf("%d",&h[i]);
        }
        for(int j=0;j<m;j++){
            for(int k=0;k<h[j];k++){
                temp[k]=str[k];
            }
            for(int l=h[j];l<len_str;l++){
                str[l-h[j]]=str[l];
            }
            for(int s=len_str-h[j];s<len_str;s++){
                str[s]=temp[s-(len_str-h[j])];
            }
        }
        cout<<str<<endl;

    }
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
const int maxn = 20005;
typedef long long ll;
int en[maxn],nt[maxn],la[maxn],len[maxn],v[maxn],owo=1;
void adg(int x,int y,int z,int vv) {
	en[++owo]=y; nt[owo]=la[x]; la[x]=owo; len[owo]=z; v[owo]=vv;
	en[++owo]=x; nt[owo]=la[y]; la[y]=owo; len[owo]=-z; v[owo]=0;
}
int S,T,z1,z2,z3,z4;

int n;
queue<int>q;
bool rd[maxn];
int path[maxn],epath[maxn];
ll ans,dis[maxn];
bool spfa() {
	for(int i=1;i<=T;i++) dis[i] = -1e16,rd[i] = 0;
	q.push(S); dis[S] = 0;
	while(q.size()) {
		int x = q.front(); q.pop(); rd[x] = 0;
		for(int it=la[x];it;it=nt[it]) {
			int y = en[it];
			if(v[it]&&dis[y]<dis[x]+len[it]) {
				dis[y] = dis[x] + len[it];
				path[y] = x;
				epath[y] = it;
				if(!rd[y]) q.push(y),rd[y] = 1;
			}
		}
	}
	if(dis[T]==(ll)-1e16) return 0;
	int mi = 0x3f3f3f3f;
	for(int p=T;p!=S;p=path[p]) mi = min(mi,v[epath[p]]);
	ans += 1ll * mi * dis[T];
	for(int p=T;p!=S;p=path[p]) {
		v[epath[p]] -= mi;
		v[epath[p]^1] += mi;
	}
	return 1;
}

int main() {
	scanf("%d",&n);
	z1 = n+n+1; z2 = n+n+2; z3 = n+n+3; z4 = n+n+4;
	S = n+n+5; T = n+n+6;
	for(int i=1;i<=n;i++) {
		int x,y,c; scanf("%d%d%d",&x,&y,&c);
		adg(i,z1,x+y,0x3f3f3f3f);
		adg(i,z2,-x+y,0x3f3f3f3f);
		adg(i,z3,x-y,0x3f3f3f3f);
		adg(i,z4,-x-y,0x3f3f3f3f);
		adg(S,i,0,c);
	}
	for(int i=1;i<=n;i++) {
		int x,y,c; scanf("%d%d%d",&x,&y,&c);
		adg(z1,i+n,-x-y,0x3f3f3f3f);
		adg(z2,i+n,x-y,0x3f3f3f3f);
		adg(z3,i+n,-x+y,0x3f3f3f3f);
		adg(z4,i+n,x+y,0x3f3f3f3f);
		adg(i+n,T,0,c);
	}
	while(spfa());
	printf("%lld",ans);
}

Measured memory_bytes: 640
n,k=map(int,input().split())
h=[int(x) for x in input().split()]

h=sorted(h)

if len(h) <= k:
    print(0)
else:
    buf=h[0:len(h)-k]
    """for i in range(k):
       del h[-1]"""
    print(sum(buf))



Measured memory_bytes: 26024
#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 int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  if(n==0){
    puts("0");
    return 0;
  }
  int b = 1;
  string ans = "";
  while(n){
    if(abs(n)&abs(b)){
      ans = "1" + ans;
      n -= b;
    }else{
      ans = "0" + ans;
    }
    b *= -2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, i, j, k, ans = 0, x;
	cin >> n;
	vector<long long> a(n);
	for (i = 0; i < n; i++) cin >> a[i];

	ans = a[0] - 1; k = 2;
	for (i = 1; i < n; i++) {
		if (a[i] >= k) {
			x = (a[i] - 1) / k;
			ans += x;
			a[i] -= x * k;
			if ((x == 0) && (a[i] == k)) k++;
		}
	}
	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 1152
<?php
fscanf(STDIN, "%d %d", $n, $m);
$ab_arr = [];
for($i = 0; $i < $n; $i++){
    $kari = trim(fgets(STDIN));
    $ab_arr_kari = explode(" ", $kari);
    $ab_arr[] = $ab_arr_kari;
}

asort($ab_arr);

$price = 0;

foreach($ab_arr as $v){
	if($m - $v[1] > 0){
        $price = $price + $v[0]*$v[1];
        $m = $m - $v[1];
    } else {
        $price = $price + $m*$v[0];
      	break;
    }
}
echo $price;
?>

Measured memory_bytes: 69236
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	int ret = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			ret += a[i];
		}
		else {
			ret -= a[i];
		}
	}
	print(ret);
}

Measured memory_bytes: 3636
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;
const int MAX = 10000;

/** Problem0565 : Lunch **/
int main()
{
	int minP=INF, minJ=INF;
	rep(i, 3) {
		int n;
		cin >> n;
		if (minP > n)
			minP = n;
	}
	rep(i, 2) {
		int n;
		cin >> n;
		if (minJ > n)
			minJ = n;
	}
	cout << minP + minJ - 50 << endl;
}

Measured memory_bytes: 1164
#-*- coding:utf-8 -*-

import math

N, K = map(int, input().split())

# 1. サイコロを振って得点にする
# 2. 得点がKより小さいならコインを振る
#   1. コインが裏なら負け
#   2. コインが表なら得点は2倍に
# 出す目それぞれについて、Kを超えるのに必要な2倍の数を求めて足し合わせる

# a2^n > K ⇔ nlog2 +loga > logK ⇔ n > (logK-loga) / log2
# aについて、勝利できる確率はn回表を出す=1/2^n
# あとはaについて1/Nを掛けて足し合わせればOK

p = 0.0

for i in range(1, N+1):
    if K > i:
        n = math.log(K/i) / math.log(2)
        n = math.ceil(n)
        p += (1/2**n) / N
    else:
        p += 1/N

print(p)







Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,b,a) for(int i=b; i>=a; i--)
#define sz(v) (int)v.size()
#define len(s) (int)s.length()
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> pi ;
typedef vector<pair<int,int> > vpi ;
typedef vector<int> vi ;
typedef long long ll ;
typedef double db ;
typedef long double ldb ;
const int mod = 1e9 + 7;
const int cmod = 998244353 ;
const ll inf = 1e18 + 5;
const db cpi = 3.14159265358 ;
ll powmod(ll a, ll b) { ll ret = 1 ; while(b) { if(b&1) ret = (ret*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return ret ; }
const int maxn = 4e5 + 5 ;
string s ;
int dp[maxn][3] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> s ;
    int n = len(s) ;
    dp[0][1] = 1 ;
    rep(i,1,n-1)
    {
        dp[i][1] = dp[i-1][2] + 1 ;
        if(s[i] != s[i-1]) dp[i][1] = max(dp[i][1], dp[i-1][1] + 1) ;
        if(i < 2) continue ;
        dp[i][2] = dp[i-2][1] + 1;
        if(i < 3) continue ;
        string a, b ;
        a = s[i] + s[i-1] ;
        b = s[i-2] + s[i-3] ;
        dp[i][2] = max(dp[i][2], dp[i-2][2] + 1) ;
    }
    int best = max(dp[n-1][1], dp[n-1][2]) ;
    cout << best << "\n" ;
    return 0 ;
}


Measured memory_bytes: 4628
n = input()

if n[-1] == "3":
    print("bon")
elif n[-1] == "0":
    print("pon")
elif n[-1] == "1":
    print("pon")
elif n[-1] == "6":
    print("pon")
elif n[-1] == "8":
    print("pon")
else:
    print("hon")

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

using namespace std;

typedef long long int llint;

llint L, R;

int main() {
	cin >> L >> R;
	if (R - L > 2017) { cout << 0 << endl; return 0; }
	llint ans = 2018;
	for (llint i = L; i <= R; i++) {
		for (llint j = i + 1; j <= R; j++) {
			ans = min(ans, ((i % 2019)*(j % 2019)) % 2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;

vector<vector<P>> hen(2500, vector<P>(0));
vector<vector<ll>> rhen(2500, vector<ll>(0));
vector<bool> check(2500,0);

void dfs(ll x,vvl &rhen ,vector<bool> &check){
    if(check[x])return;
    check[x]=1;
    for(auto p: rhen[x])dfs(p,rhen,check);
    return;
}


int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    ll PP;
    cin >> PP;
    vector<ll> A(M,0);
    vector<ll> B(M,0);
    vector<ll> C(M,0);
    for(ll i=0;i<M;i++){
        cin>>A[i]>>B[i]>>C[i];
        A[i]--;B[i]--;C[i]-=PP
    ;}
    vector<vector<P>> hen(N, vector<P>(0));
    vector<vector<ll>> rhen(N, vector<ll>(0));
    for(ll i=0;i<M;i++){
        hen[A[i]].emplace_back(P(B[i],C[i]));
        rhen[B[i]].emplace_back(A[i]);
    ;}

    dfs(N-1,rhen,check);

    vector<ll> d(N,-INF);
    d[0]=0;
    //ベルマンフォード法
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            if(d[j]==-INF)continue;
            for(auto p: hen[j]){
                if(d[p.first]<d[j]+p.second){
                d[p.first]=d[j]+p.second;
                if(i==N-1&&check[p.first]){cout<<-1<<endl;return 0;}
                }
            ;}
        ;}
    ;}
    ll ans=d[N-1];
    //行けない場合
    if(ans==-INF){
        cout<<-1<<endl;return 0;
    }

    cout<<max(ans,0LL)<<endl;
    

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
vector<int> parent;
long score[100000];
void  create(int n)
{
    parent.clear();
    
    for(int i=0;i<n;i++)
    {
        parent.push_back(i);
       
        
    }
    
    
    
}

int find(int x) 
    { 
        
        if (parent[x] != x) { 
  
    
            parent[x] = find(parent[x]); 
  
        } 
  
        return parent[x]; 
    } 
    
void uniono(int x,int y)
{
    
    int i= find(x);
    int u= find(y);
    
if(score[x]>score[y])    
parent[y]=i;
else
parent[x]=u;

}

int main()
{
   string s,t;
   cin>>s>>t;
  // int a1[26];
 //  int a2[26];
 //  memset(a1,0,sizeof(a1));
  // memset(a2,0,sizeof(a2));
  int sum=0;
   for(int i=0;i<s.size();i++)
   {
    if(s[i]!=t[i])sum++;
       
   }
   
   cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3920
n, q = map(int, input().split())
s = input()
cnt_list = [0]*(n)
tmpi = 0
for i in range(1, n):
    if s[i-1] == "A":
        if s[i] == "C":
            cnt_list[i] = cnt_list[i-1] + 1
        else:
            cnt_list[i] = cnt_list[i-1]
    else:
        cnt_list[i] = cnt_list[i-1]

for i in range(q):
    l, r = map(int, input().split())
    print(cnt_list[r-1] - cnt_list[l-1])

Measured memory_bytes: 51288
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int A,B;
  cin>>A>>B;
  int count=0;
  for(int i=A;i<=B;i++){
    int s,t,u,v;
    s=i%10;
    t=i/10000%10;
    u=i/10%10;
    v=i/1000%10;
    if(s==t&&u==v){
      count++;
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 256
A, B, M = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
x = Array.new(M)
y = Array.new(M)
c = Array.new(M)
for i in 0..(M-1)
  x[i], y[i], c[i] = gets.split.map(&:to_i)
end

amin = 10**6
bmin = 10**6
a.each{|an| amin = [amin, an].min}
b.each{|bn| bmin = [bmin, bn].min}

ans = amin+bmin
for i in 0..(M-1)
  sum = a[x[i]-1]+b[y[i]-1]-c[i]
  ans = [ans, sum].min
end
puts ans

Measured memory_bytes: 22820
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>


using namespace std;

int main(){
   int n[4];
   for(int i =0; i < 4; i++){
      cin >> n[i];
   }
   sort(n,n+4);
   if(n[0]==1 && n[1]==4&&n[2]==7&&n[3]==9){
      cout <<"YES"<<endl;
   }
   else cout <<"NO"<<endl;


   return 0;
}


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


int main () {
    int n ;
    cin >> n ;
    vector<string> vec(n);
    rep(i, n){
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    map<string,int> maps ;
    rep(i, n){
        if(maps.count(vec[i])){
            maps.at(vec[i])++ ;
        }
        else {
            maps[vec.at(i)] = 1;
        }
    }
    int max_num = 0 ;
    vector<string> ans ;
    for(auto p :maps){
        auto t = p.first;
        auto k = p.second;
        if(max_num < k){
            max_num = k ;
            ans = {};
            ans.push_back(t);
        }
        else if(max_num == k){
            ans.push_back(t);
        }
        else {
            continue;
        }

    }
    sort(ans.begin(), ans.end());
    rep(i, ans.size()){
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 28404
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

int main(){
	string w;
	cin >> w;
	vector<int> a(26,0);
	
	for(int i=0;i<w.size();i++){
		a[(int)(w[i]-'a')]++;
	}
	
	for(int i=0;i<26;i++){
		if(a[i]%2!=0){
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

type Pair struct {
	First  int64
	Second int
}

func prime_factor(n int64) []Pair {
	ret := make([]Pair, 0, 0)
	var num int

	for i := int64(2); i*i <= n; i++ {
		if n%i != 0 {
			continue
		}
		num = 0
		for n%i == 0 {
			num++
			n /= int64(i)
		}
		ret = append(ret, Pair{First: i, Second: num})
	}
	if n != 1 {
		ret = append(ret, Pair{First: n, Second: 1})
	}
	return ret
}

func gcd(x, y int64) int64 {
	if y == 0 {
		return x
	} else {
		return gcd(y, x%y)
	}
}

func main() {
	var a, b int64
	fmt.Scan(&a, &b)

	g := gcd(a, b)
	fmt.Println(len(prime_factor(g)) + 1)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#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=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

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

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1234567;
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<lcm(a,b)<<endl;
	cout<<endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

map<ll,ll> res;
map<ll,ll> prime_fact(ll n){
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			++res[i];
			n/=i;
		}
	}
	if(n!=1) res[n]=1;
	return res;
}
ll fc[200005],fv[200005];
ll cb(ll n,ll r){
  if(n==r) return 1;
  ll ret=0;
  ret=fc[n]*fv[n-r]%mod*fv[r]%mod;
  return ret;
}
ll mod_inverse(ll a) {
    ll ret=1L;
    ll m=1e9+5L;
    while(m){
      if(m%2){
        ret=(ret*a)%mod;
      }
      m=m/2;
      a=(a*a)%mod;
    }
    return ret;
}

ll N,M;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>M;
prime_fact(M);

fc[0]=1; fv[0]=1;
rep1(i,2*N){
	fc[i]=i*fc[i-1]%mod;
}
rep1(i,2*N){
	fv[i]=mod_inverse(i)*fv[i-1]%mod;
}

ll ans=1;
map<ll,ll>::iterator it;
for(it = res.begin(); it!=res.end(); it++){
    ll p=it->first;
    ll q=it->second;
    ans=ans*cb(N-1+q,q)%mod;
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 3328
def mizu(h):
    global count
    # 終端処理
    if len(h) is 0:
        return
    if len(h) is 1:
        count += h[0]
        return
    # その範囲の最小値
    m = min(h)
    count += m
    # 残りの高さ
    h = [i - m for i in h]
    while 0 in h:
        # （最小値だった）0の箇所で分割
        mizu(h[:h.index(0)])
        h = h[h.index(0)+1:]
    mizu(h)


N = int(input())
h = list(map(int, input().split()))

count = 0
mizu(h)

print(count)


Measured memory_bytes: 38512
#include<iostream>
using namespace std;
int main(){
	int n; cin >>n;
	int i=1;
	while(++i<=n){
		int x=i;
		if(x%3==0){
			cout << " "<< i;
			continue;
		}
		while(x){
			if(x%10==3){
				cout << " "<< i;
				break;
			}
			x/=10;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 

 int main(){
   ll n,a,b ; cin>>n>>a>>b ;
   vector<ll> A(n) ;
   rep(i,n) cin>>A[i] ;
   ll ans=0 ;
   rep(i,n-1){
     ans+= min(a*(A[i+1]-A[i]),b) ;
   }
   cout<<ans<<endl ;
   return 0 ;
}



Measured memory_bytes: 4052
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($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)*}
    };
}

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

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<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        nums: [usize;2],
    };

    println!("{}", solve(nums[0],nums[1]));
}

fn solve(n: usize, i :usize) -> usize {
    return n - i + 1;
}

macro_rules! tests {
    ($($name:ident:[$( $args:expr ),*] => $output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output,super::solve($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:[15,11]=>5,
    test2:[1,1]=>1,
    test3:[4,2]=>3,
}


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

int main()
{
    int n,k,x, b;
    map <int, int>cnt;
    cin >> n >> k;
    for(int i=1; i<=k; i++){
        cin >> x;
        for(int j=0; j<x; j++){
            cin >> b;
            cnt[b]++;
        }
    }
    cout << n - cnt.size();
    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll v[6];

int main() {
  while (true) {
    ll total = 0;
    REP(i, 6) {
      scanf("%lld", &v[i]);
      total += v[i];
    }
    if (total == 0) { break; }
    ll a = v[0] + v[3];
    ll b = v[1] + v[4];
    ll c = v[2] + v[5];
    ll ans = 0;
    ans = max(ans, a / 3 + b / 3 + c / 3);
    a--; b--; c--;
    if (a >= 0 && b >= 0 && c >= 0) {
      ans = max(ans, 1 + a / 3 + b / 3 + c / 3);
    }
    a--; b--; c--;
    if (a >= 0 && b >= 0 && c >= 0) {
      ans = max(ans, 2 + a / 3 + b / 3 + c / 3);
    }
    printf("%lld\n", ans);
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int MOD = 1e9 + 7;

vi adj[2001];
int dist[2001];
int dist2[2001];
int cnt;
int k;
bool visited[2001];

void dfs(int u)
{
	visited[u] = true;
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(!visited[v])
		{
			dist[v] = dist[u] + 1;
			if(dist[v] > k/2) cnt++;
			dfs(v);
		}
	}
}

void dfs2(int u)
{
	visited[u] = true;
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(!visited[v])
		{
			dist2[v] = dist2[u] + 1;
			if(dist2[v] > k/2) cnt++;
			dfs2(v);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n >> k;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	int ans = n;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < adj[i].size(); j++)
		{
			int v = adj[i][j];
			int u = i;
			memset(dist, 0, sizeof(dist));
			memset(dist2, 0, sizeof(dist));
			memset(visited, 0, sizeof(visited));
			dfs(u);
			memset(visited, 0, sizeof(visited));
			dfs2(v);
			cnt = 0;
			for(int l = 0; l < n; l++)
			{
				if(dist[l] > (k-1)/2 && dist2[l] > (k-1)/2)
				{
					cnt++;
				}
			}
			ans = min(ans, cnt);
		}
	}
	for(int i = 0; i < n; i++)
	{
		dfs(i);
		memset(dist, 0, sizeof(dist));
		memset(visited, 0, sizeof(visited));
		ans = min(ans, cnt);
		cnt = 0;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 512
N = int(input())
ans = []
lis = []
for i in range(N):
    lis.append(i + 1)
if N % 2 == 0:
    M = (N - 2) * N // 2
    for i in range(1, N):
        for j in range(1, N):
            if j != i and i != lis[-j]:
                tmp = sorted([i, lis[-j]])
                if tmp not in ans:
                    ans.append(tmp)
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))
else:
    M = (N - 1) ** 2 // 2
    for i in range(1, N):
        for j in range(2, N):
            if j != i + 1 and i != lis[-j]:
                tmp = sorted([i, lis[-j]])
                if tmp not in ans:
                    ans.append(tmp)
    for i in range(1, N):
        ans.append([N, i])
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a[100005];
int main(){
	scanf("%d%d", &n, &k);
	for(i=1; i<=n; i++){
		scanf("%d", &a[i]);
	}
	sort(a+1, a+n+1);
	for(m=a[n], i=k; i<=n; i++){
		m = min(m, a[i]-a[i-k+1]);
	}
	printf("%d\n", m);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cctype>
#include<map>
#include<set>
#include<deque>
#include<iomanip>
typedef long long LL;
using namespace std;
int main()
{
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int cnt = 0;
	for(int i = 0;i<=a;i++)
	{
		for(int j = 0;j<=b;j++)
		{
			for(int k = 0;k<=c;k++)
			{
				if(500*i+100*j+50*k==x) cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    int ans = 0;
    for (int i=1; i<n-1; i++) {
        vector<int> x(3);
        x[0] = p[i-1];
        x[1] = p[i];
        x[2] = p[i+1];
        sort(ALL(x));
        if (p[i] == x[1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    votes = gets.chomp.split
    h = Hash.new(0)
    votes.each{|v| h[v] += 1}
    winners = h.find_all{|k, v| v == h.values.max}
    if winners.length > 1
        puts "TIE"
    else
        winner = winners[0][0]
        w, h = 0, Hash.new(0)
        h["?"] = 0
        votes.each_with_index{|v, i|
            if v == winner
                w += 1
            else
                h[v] += 1
            end
            if h.all?{|k, v| w > v + n - i - 1}
                puts "#{winner} #{i + 1}"
                break
            end
        }
    end
end



Measured memory_bytes: 6880