akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int[][][] list = new int[4][3][10];
		for (int i = 0; i < a; i++) {
			int b = scanner.nextInt() - 1;
			int f = scanner.nextInt() - 1;
			int r = scanner.nextInt() - 1;
			int v = scanner.nextInt();
			list[b][f][r] += v;
		}

		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					System.out.print(" " + list[i][j][k]);
				}
				System.out.println();
			}
			if (i != 3)
				System.out.println("####################");
		}

	}
}



Measured memory_bytes: 29176
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	double n,sum=0;

	cin >> n;
	vector<double> a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	rep(i, n-1) {
		a[i + 1] = (a[i] + a[i + 1]) / 2;
	}
	cout << a[n-1];
}

Measured memory_bytes: 256
s = input()
for c in s:
    if not '0'<=c<='9':
        print('NA')
        exit(0)
a = int(s[:2])
b = int(s[2:])
if 1<=a<=12 and 1<=b<=12:
    print('AMBIGUOUS')
elif 1<=a<=12:
    print('MMYY')
elif 1<=b<=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
  
  long long x;
  cin >> x;

  long long p = 100,co=0;
  while(p < x){
      p += p/100;
    co++;
  }
  cout << co << endl;

    return 0;
}



Measured memory_bytes: 3676
N = int(input())
H = list(map(int, input().split()))
H2 =[0]*(N-1)
for i in range(N-1):
    H2[i] = H[i]-H[i+1]
ans = 0
cnt = 0
for i in range(N-1):
    if H2[i] >= 0:
        cnt += 1
    elif H2[i] < 0:
        if ans < cnt:
            ans = cnt
            cnt = 0
        else:
            cnt = 0
if ans < cnt:
            ans = cnt
print(ans)

Measured memory_bytes: 14228
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int h = Integer.parseInt(str[0]);
    int n = Integer.parseInt(str[1]);
    String[] a = in.readLine().split(" ");
    int[] a_array = new int[n];
    for(int i = 0; i<n; i++){
      a_array[i] = Integer.parseInt(a[i]);
      h -= a_array[i];
    }
    System.out.println(h<=0?"Yes":"No");
  }
}

Measured memory_bytes: 33372
import java.util.*;
import java.lang.Math;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int human[] = new int[n];
      	int as[] = new int[n];
      	int al;
      	int acnt;
      	List wList = new ArrayList<Integer>();
      	boolean hs[] = new boolean[n];
      	boolean con;
      	int np = (int)Math.pow(2,n);
      	int count;
      	int count_max = 0;
      	int istack;
      	int istack2;
      
      	count = 0;
      	for(int i = 0;i < n;i++){
          as[i] = sc.nextInt();
          count += as[i];
          for(int j = 0;j < as[i];j++){
            istack = sc.nextInt()-1;
            if(sc.nextInt() == 1) wList.add(istack);
            else wList.add(istack + 100);
          }	
        }
      	al = count;
      
      	for(int i = 0;i < np;i++){
        	istack = i;
          	count = 0;
          	con = true;
          	for(int j = 0; j < n && istack > 0;j++){
          	  if(istack%2 == 1) {
                hs[j] = true;
                count++;
              }
          	  else hs[j] = false;
          	  istack /= 2;
            }
          	acnt = 0;
          	for(int j = 0;j < al && con;j++){
              if(hs[acnt]){
                for(int k = 0;k < as[acnt] && con;k++){
                  istack = (int)wList.get(j+k);
                  if(istack < 99){
                  	if(!hs[istack]) con = false; 
                  }
                  else{
                    if(hs[istack - 100]) con = false; 
                  }
                }
              }
              j += (as[acnt] - 1);
              acnt++;
            }
          	if(con){
              if(count_max < count) count_max = count;
            }
        }      	
      
      	System.out.println(count_max);
	}
}

Measured memory_bytes: 37620
//atcoder library for java 感謝します。
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

 
public class Main {
	static final long MOD=1000000007;//998244353;
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		int N=sc.nextInt();
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				for (int j2 = 0; j2 <= 10; j2++) {
					if ((i>>j2)%2!=(j>>j2)%2) {
						out.print((j2+1)+" ");
						break;
					}
				}
			}
			out.println();
		}
		out.flush();
	}
		static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 42696
H, W = map(int, input().split())
a = []
block = '#' * (W+2)
for _ in range(H):
    a.append(input())
for i in range(H):
    a[i] = '#' + a[i] + "#"
a.insert(0, block)
a.insert(H+1, block)
# print(a,block)
for i in range(H+2):
    print(a[i])

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);

        int count = 0;
        while (true) {

            N = N - (2 * D + 1);

            if (N > 0) {
                count++;
            } else {
                count++;
                break;
            }

        }

        System.out.println(count);

        scanner.close();

    }

}


Measured memory_bytes: 21972
#include <cstdio>
#include <queue>
#include <utility>

using namespace std;

const int m = 100000000;

priority_queue< pair< int, int > > Q;
int d[m], n, s, x[m], y[m];

int main()
{
    scanf( "%d %d\n", &n, &s );
    Q.push( make_pair( 0, -1000000000 ) );
    for( int i = 0; i < s; i++ )
    {
        scanf( "%d %d\n", &x[i], &y[i] );
        d[x[i]] += y[i];
        Q.push( make_pair( d[x[i]], -x[i] ) );
        while( 1 )
        {
            pair< int, int > p = Q.top();
            if( p.first == d[-p.second] )
            {
                printf( "%d %d\n", -p.second, p.first );
                break;
            }
            Q.pop();
        }
    }
    return 0;
}


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

#define ll long long
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define pll pair<ll,ll>

using namespace std;
const ll maxn=4e6+100;
const ll mod = 998244353;

ll a[maxn];
ll c[maxn];
ll d;
map<ll,ll> mp;
ll f( ll n )
{
    if (n==1) return d;
    if (n==0) return 0;
    if (mp[n]!=0) return mp[n];
    ll ans=1e18;
    if (ans/d>n) ans=n*d;

    for (int i=1;i<=3;i++)
    {
        ll k=(n/a[i])*a[i];
        ans=min(ans,abs(k-n)*d+c[i]+f(k/a[i]));

    }
    for (int i=1;i<=3;i++)
    {
          ll k=((n+a[i]-1)/a[i])*a[i];
        ans=min(ans,abs(k-n)*d+c[i]+f(k/a[i]));
    }
    return mp[n]=ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
  //  freopen("WEDDING.INP", "r", stdin);
   //  freopen("WEDDING.OUT", "w", stdout)
   ll t;
    cin>> t;
    a[1]=2;
    a[2]=3;
    a[3]=5;
     while (t--)
     {
         ll n;
         mp.clear();
          cin>> n>>c[1]>>c[2]>>c[3]>>d;
          cout <<f(n)<<endl;
     }
}


Measured memory_bytes: 4416
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        String word = sc.next();

        String[] stepList = word.split("");
        boolean isGood = true;

        for (int i = 0; i < stepList.length; i++) {
            if (i % 2 == 0) {
                if (stepList[i].equals("L")) {
                    isGood = false;
                }
            } else {

                if (stepList[i].equals("R")) {
                    isGood = false;
                }

            }
            if (!isGood) {
                break;
            }
        }

        String result = "";
        if (isGood) {
            result = "Yes";
        } else {
            result = "No";
        }

        System.out.println(result);
    }
}


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

using namespace std;

typedef long long ll;
typedef double dbl;

#define size(s) (ll) (s).size()
#define all(s) (s).begin(), (s).end()
#define rall(s) (s).rbegin(), (s).rend()

const ll INF = 1e9, TMP = -INF * 2 + 1;

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

	cin.tie(nullptr);
	cout.tie(nullptr);

#ifdef _MINEM
	freopen("file.in", "r", stdin);
	freopen("file.out", "w", stdout);
#else
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
#endif

	ll n, sum = 0;

	cin >> n;

	vector<ll> a(n), b(n);

	for (ll i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	for (ll i = n - 1; i >= 0; i--) {
		if (((sum + a[i]) % b[i]) == 0) continue;
		sum += (b[i] - ((sum + a[i]) % b[i]));
	}

	cout << sum << '\n';

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int k;
  cin >> k;
  int sum=0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    if(x>=k-x && k-x>=0) {    
      sum+=(k-x)*2;}
    else if(x>=x-k && x-k>=0) {
      sum+=(x-k)*2;}
    else if(x<=k-x && k-x>=0) {
      sum+=x*2;}
    else if(x<=x-k && x-k>=0) {
      sum+=x*2;}
    }
  cout << sum << endl;
  }
      


Measured memory_bytes: 256
#include<stdio.h>
int solve(int i,int m);
int a[21];
int n;
int main()
{
  int i,j,q,m,sol;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    i=0;
    scanf("%d",&m);
    sol=solve(i,m);
    if(sol==0)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i, int m){
  int res;
  if(m==0)return 0;
  if(i>=n)return 1;
  if(solve(i+1,m)==0 || solve(i+1,m-a[i])==0)return 0;
  else return 1;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int cnt[26] = {};
    rep(i, S.length()) {
        cnt[S[i] - 'a']++;
    }
    //rep(i, 26) dump(cnt[i]);
    int ans = S.length() * (S.length()-1) / 2 + 1;
    rep(i, 26)  ans -= cnt[i] * (cnt[i]-1) / 2;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<cstdio>

using namespace std;

int main(void)
{
	double a, b, c, d, e, f, x, y;
	
	while(cin >> a >> b >> c >> d >> e >> f){
		y = (c*d - a*f) / (b*d - a*e);
		x = (c - b*y) / a;
		
		if(x == -0)
		x = 0;
		if(y == -0)
		y = 0;
		
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 1236
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long H = sc.nextLong();
    long W = sc.nextLong();
    
    long count = 0;
    for(long i = 0; i < N; i++){
      long A = sc.nextLong();
      long B = sc.nextLong();
      if(A >= H && B >= W) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 26452
#include<stdio.h>
int main(void)
{
	int w,h,n,x,y,a,s[100][100]={0},z,i,j;
	scanf("%d %d %d", &w, &h, &n);
	for(z=0; z<n; z++)
	{
		scanf("%d %d %d", &x, &y, &a);
		if(a==1)
		{
			for(i=0; i<x; i++)
			{
				for(j=0; j<h; j++)
				s[i][j]=1;
			}
		}
		if(a==2)
		{
			for(i=x; i<w; i++)
			{
				for(j=0; j<h; j++)
				s[i][j]=1;
			}
		}
		if(a==3)
		{
			for(i=0; i<w; i++)
			{
				for(j=0; j<y; j++)
				s[i][j]=1;
			}
		}
		if(a==4)
		{
			for(i=0; i<w; i++)
			{
				for(j=y; j<h; j++)
				s[i][j]=1;
			}
		}
	}
	a=0;
	for(i=0; i<w; i++)
	{
		for(j=0; j<h; j++)
		a+=s[i][j];
	}
	printf("%d\n", w*h-a);
	
	return 0;
}

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


Measured memory_bytes: 3240
#include<bits/stdc++.h>
  using namespace std;
long long n,x;
inline void into(){
  scanf("%lld%lld",&n,&x);
}
inline void work(){
}
long long gcd(long long a,long long b){
  while (b){
  	swap(a,b);
  	b%=a;
  }
  return a;
}
inline void outo(){
  printf("%lld\n",3*(n-gcd(n,x)));
}
int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main (String args[]) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int S[] = new int[n];
	for(int i = 0;i < n;i++) S[i] = sc.nextInt();
	int q = sc.nextInt();
	int T[] = new int[q];	
	for(int i = 0;i < q;i++) T[i] = sc.nextInt();
	int cnt = 0;
	for(int j = 0;j < q;j++){
	    for(int i = 0;i < n;i++){
		if(S[i] == T[j]){
		    cnt++;
		    break;
		}
	    }	    
	}
	System.out.println(cnt);
    }
}



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

#define MaxW 1000
#define MaxH 1000
#define MaxN 1000
#define INF 99999
int H,W,N;
int d[MaxN + 1][MaxN + 1];
char pos[MaxH][MaxW];
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
bool visited[MaxH][MaxW];

typedef struct Node{
    int x,y;
}Node;

bool judge(int x, int y){
    if (x >= 0 && x < H && y>= 0 && y< W){
        return true;
    }
    return false;
}

int bfs(int s, int e){
    queue<Node> Q;
    int sx,sy,ex,ey;//record the position of start and end point
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            visited[i][j] = false;
            d[i][j] = 0;
            if (pos[i][j] - '0' == s){
                sx = i;sy = j;
            } else if(pos[i][j] - '0' == e){
                ex = i;ey = j;
            }
        }
    }
    Node S;
    S.x = sx;
    S.y = sy;
    Q.push(S);
    visited[sx][sy] = true;
    bool find = false;

    while(!Q.empty()){
        Node T = Q.front();
        Q.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = T.x + dx[i];
            int ny = T.y + dy[i];
            if (!visited[nx][ny] && judge(nx, ny) && pos[nx][ny] != 'X') {
                Node p;
                p.x = nx;
                p.y = ny;
                Q.push(p);
                visited[nx][ny] = true;
                d[nx][ny] = d[T.x][T.y] + 1;
            }
            if (nx == ex && ny == ey){
                find = true;
                break;
            }
        }
        if(find == true)
            break;
    }
    return d[ex][ey];
}

int main(){
    while(cin>>H>>W>>N){
        if (H == 0 && W == 0 )
            break;
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                cin>>pos[i][j];
                if (pos[i][j] == 'S')
                    pos[i][j] = '0';
            }
        }
        for (int k = 0; k < H; ++k) {
            for (int i = 0; i < W ; ++i) {
                d[k][i] = 0;
            }
        }int t = 0;
        for (int l = 0; l < N; ++l) {
            t += bfs(l,l+1);
        }

        cout<<t<<endl;
    }

    return 0;
}


Measured memory_bytes: 8924
#include <bits/stdc++.h>
using namespace std;
vector<long double> v; long double x;
int main() {
	while(cin >> x) v.push_back(x);
	sort(v.begin(), v.end());
	cout << v.back() - v.front() - 0.009L << endl;
	return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("Yes"):fin("No");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    rep(i,n)v[i]--;
    int ans=0;
    rep(i,n-1){
        if(v[i]==i){
            swap(v[i],v[i+1]);
            ans++;
        }
    }
    if(v[n-1]==n-1){
        swap(v[n-1],v[n-2]);
        ans++;
    }
    fin(ans);
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <ctime>
#include <deque>
#include <unordered_map>
#include <map>
#include <random>
#include <cstdio>
#include <string>
#include <cctype>
#define int long long
#define pb push_back
#define eb emplace_back
#define rs resize
#define ld long double
#define vi vector<int>


using namespace std;

const double PI = atan2(0, -1);

void solve() {
    double r;
    cin >> r;
    cout << (2 * r * PI);
}


signed main() {
    ///  freopen("salesman.in", "r", stdin);
   //   freopen("salesman.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout.precision(30);
    int t = 1;
    while(t--)
    solve();
    //   system("pause");
}

Measured memory_bytes: 3804
import sys

def main():
    score1 = []
    for i in range(4):
        score1.append(int(input()))
    score1.sort()
    score2 = []
    for i in range(2):
        score2.append(int(input()))
    score2.sort()

    print(sum(score1[1:]+score2[1:]))
    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int M = 1e9 + 7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};


int main() {
  int n;
  cin >> n;
  int m = 2;
  int s = 0;
  rep(i,n) {
    int a = 0;
    cin >> a;
    s += a%2;
  }
  if (s%2) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 3636
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

import itertools

ptn = list(itertools.permutations(range(1, n + 1)))
a = ptn.index(p)
b = ptn.index(q)
ans = abs(a - b)

print(ans)

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

using namespace std;

int main() {
    int N;
    cin >> N;/* code */
    vector<int> A(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    sort(A.begin(),A.end());
    cout << A.at(N-1)-A.at(0) << endl;

    
    
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<cstring>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int           long long
#define umapii        unordered_map<int,int>
#define ps(x,y)       fixed<<setprecision(y)<<x // sets precision upto required digits
#define arr(a,n)      int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define outarr(a,n)   for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define mod           1000000007
#define ff            first
#define big           1e15
#define ss            second
#define add           push_back
#define remove        pop_back
#define mapii         map<int,int>
#define large         *max_element
#define small         *min_element
#define float         double
#define pqi           priority_queue<int>
#define mpqi          priority_queue<int,vector<int>,greater<int>>
#define in(n)         int n;cin>>n;
#define w(t)          int t;cin>>t;while(t--)
#define vi            vector<int>
#define vivi          vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;



bitset<1000005>b;
vi v;

void seive() {
    b.set();
    for (int i = 4; i <= 1000000; i += 2) {
        b[i] = 0;
    }
    b[1] = b[0] = 0;
    v.add(2);
    for (int i = 3; i <= 1000000; i += 2) {
        if (b[i]) {
            v.add(i);
            for (int j = i * i; j <= 1000000; j += i) {
                b[j] = 0;
            }
        }
    }
}


int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
#endif
    seive();
    int n;
    cin >> n;
    int ans = 0;
    for (int i = n - 1; i >= 1; i--) {
        int temp = i;
        int sub = 1;
        for (int j = 0; v[j]*v[j] <= temp; j++) {
            int cnt = 0;
            while (temp % v[j] == 0) {
                cnt++;
                temp = temp / v[j];
            }
            sub = sub * (1 + cnt);
        }
        if (temp != 1) {
            sub *= 2;
        }
        ans += sub;
    }
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;

template <typename T>
class BinaryIndexedTree {  // 1-indexed
  int N;
  vector<T> bit;

 public:
  BinaryIndexedTree(int N) : N(N) { bit.assign(N, 0); }

  void add(int index, T num) {
    for (int x = index; x <= N; x += x & -x) bit[x] += num;
  }

  T sum(int index) {
    int ret = 0;
    for (int x = index; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  auto aa = a;
  sort(aa.begin(), aa.end());
  int right = n, left = -1;
  while (right - left > 1) {
    int mid = (right + left) / 2;
    int med = aa[mid];
    auto b = a;
    for (auto &x : b) {
      if (x < med)
        x = -1;
      else
        x = 1;
    }
    for (int i = 1; i < n; ++i) {
      b[i] += b[i - 1];
    }
    BinaryIndexedTree<int> BIT(300001);
    ll num = 0;
    BIT.add(100001, 1);
    for (auto x : b) {
      num += BIT.sum(x + 100001);
      BIT.add(x + 100001, 1);
    }
    // cout << med << " " << num << endl;
    ll m = ((ll(1 + n) * n) / 2);
    if (num >= m / 2 + m % 2) {
      left = mid;
    } else {
      right = mid;
    }
  }
  cout << aa[left] << endl;
}

Measured memory_bytes: 2560
N = int(input())
A = list(map(int, input().split()))

counts = {}
for a in A:
    if a not in counts:
        counts[a] = 1
    else:
        counts[a] += 1
    
ans = 0
for key,val in counts.items():
    if val > key:
        ans += val - key
    if val < key:
        ans += val

print(ans)

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

int main()
{
	int n, sum = 0;
	cin >> n;
	int A[n];
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			sum += A[i] * A[j];
		}
	}
	cout << sum;
}

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

using namespace std;

int main() {
    string s;
    while (getline(cin, s)) {
        stringstream ss;
        ss << s;

        string w;
        stack<double> st;
        while (ss >> w) {
            int sz = w.size();
            if (isdigit(w[sz - 1])) st.push(atof(w.c_str()));
            else {
                double a, b;
                b = st.top(); st.pop();
                a = st.top(); st.pop();

                switch (w[0]) {
                    case '+': st.push(a + b); break;
                    case '-': st.push(a - b); break;
                    case '*': st.push(a * b); break;
                    case '/': st.push(a / b); break;
                }
            }
        }

        printf("%.10f\n", st.top());
    }

    return 0;
}


Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define endl "\n"
#define nl cout<<endl
#define pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define txti freopen("input.txt", "r", stdin);
#define txto freopen("output.txt", "w", stdout);


bool compare(char &s1,char &s2) 
{ 
    return s1 > s2; 
} 

bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
   
    if(a.first<b.first )
        return true;
    if( a.first==b.first && a.second<b.second )
        return true;
        
    return false;
    
}
//ll const mod = 1e9+7;
ll const inf = 1e7+1;
ll f[inf];
void sieve()
{
    memset(f, 0, sizeof f);

    for(ll i=2; i < inf; i++){

        for(ll j=i; j < inf; j+=i)
            ++f[j];

    }
}



void solve()
{   
    ll n; cin >> n;

    ll ans = 0;
    
    for(ll k=1; k<=n; k++){
        ans += ( k*(f[k]+1) );
    }
    cout << ans <<endl;
}  



int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/
            
       sieve();
        ll t=1;
        //ll t;cin>>t;
        while(t-->0){
            solve();
            
        }
        
        

       
    return 0;
}




Measured memory_bytes: 81788
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
 
struct Puddle{
    int start, end, area;
};
 
int main(){
    string str;
    cin >> str;
    int n = str.size(), overall = 0;
    stack<Puddle> S;
    stack<int> slope;
 
    for(int i = 0; i < n; i++){
        if(str[i] == '\\'){
            slope.push(i);
        } else if(str[i] == '/'){
            if(!slope.empty()){
                int b = slope.top();
                Puddle temp;
                temp.start = b;
                slope.pop();
                temp.end = i;
                temp.area = (temp.end - temp.start);
                overall += temp.area;
                while( !S.empty() ){
                    if(temp.start < S.top().start){
                        temp.area += S.top().area;
                        S.pop();
                    } else {
                        break;
                    }
                }
                S.push(temp);
            }
        }
    }
    cout << overall << endl;
    int m = S.size(), A[m];
    cout << m;
    for(int i = 0; i < m; i++){
        A[m - i - 1] = S.top().area;
        S.pop();
    }
    for(int i = 0; i < m; i++)
        cout << " " << A[i];
    cout << endl;
}

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

int main() {
  int A,B,K;
  cin >>A>>B>>K;
  int count=0;
  for(int i=min(A,B);i>0;i--){
    if(A%i==0&&B%i==0){
      count++;
      if(count==K){
        cout<<i<<endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  def nextInt() = sc.next.toInt

  def maxProfit(n: Int, maxv: Int, minv: Int): Int = {
    if (n == 0)
      maxv
    else {
      val r = nextInt
      maxProfit(n - 1, maxv max (r - minv), minv min r)
    }
  }

  val n = nextInt
  val r0 = nextInt
  val r1 = nextInt

  println(maxProfit(n - 2, r1 - r0, r0 min r1))
}



Measured memory_bytes: 120664
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt()-1;
        int Y = sc.nextInt()-1;

        int[] ans = new int[N-1];
        for (int i=0;i<N;i++) {
            for (int j=i+1;j<N;j++) {
                int min = j-i;
                min = Math.min(min, Math.abs(X-i)+Math.abs(Y-j)+1);
                min = Math.min(min, Math.abs(Y-i)+Math.abs(X-j)+1);
                ans[min-1]++;
            }
        }
        for (int i=0;i<N-1;i++) {
            System.out.println(ans[i]);
        }
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//long long n, A[1000000000];
	//ll n, m, q;
	ll x[51][51][2501] = { {{}} };
	ll n;
	cin >> n;
	cin >> a;
	ll y[51] = {};
	for (int i = 1; i <= n; i++)
	{
		cin >> y[i];
	}
	x[0][0][0] = 1;

	for (int i = 0; i <= n; i++)
	{
		for (int k = 0; k <= i; k++)
		{
			for (int l = 0; l <= 50 * k; l++)
			{
				if (l - y[i] >= 0&&i-1>=0&&k-1>=0)
				{
					x[i][k][l] = x[i - 1][k][l] + x[i - 1][k - 1][l - y[i]];
				}
				else if(i - 1 >= 0)
				{
					x[i][k][l] = x[i - 1][k][l];
				}
			}
		}
	}

	/*for (int i = 0; i <= n; i++)
	{
		for (int k = 0; k <= i; k++)
		{
			for (int l = 0; l <= 50 * k; l++)
			{
				if (x[i][k][l] != 0)
				{
					cout << x[i][k][l] << endl;
					cout << "i=" << i << endl;
					cout << "k=" << k << endl;
					cout << "l=" << l << endl;

				}
			}
		}
	}*/
	//cout   << endl;
	//cout  << endl;

	//for (int i = 1; i <= n; i++)
	//{
		for (int k = 1; k <= n; k++)
		{
			c += x[n][k][k*a];
		/*	cout << x[n][k][k*a] << endl;
			cout << "k=" << k << endl;
			cout << "k*a=" << k*a << endl;
		*/}
	//}

	cout << c << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//accumulate(x, x + a, 0);
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}



Measured memory_bytes: 51072
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;

int main(void) {
   ll A,B;
   cin>>A;
   cin>>B;
   for (ll i=1;i<=3;i++) {
      if (A!= i && B!= i) cout<<i<<endl;
   }

   return 0;
}

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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

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

  ll n;
  cin >> n;
  vector < pair < ll, ll > > v(n);
  for(int i = 0; i < n; i++) cin >> v[i].second >> v[i].first;

  sort(v.begin(), v.end());

  bool ok = true;
  ll time = 0;
  for(int i = 0; i < n; i++){
    time += v[i].second;
    if(time > v[i].first){
      ok = false;
      break;
    }
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3456
void main()
{
    long n = rdElem;

    Graph[] g;
    foreach (i; 1 .. n)
    {
        foreach (j; i+1 ..n+1)
        {
            if (i + j != (n + !(n & 1))) g ~= Graph(i, j);
        }
    }

    g.length.writeln;
    foreach (x; g)
    {
        writeln(x.a, " ", x.b);
    }
}

struct Graph
{
    long a, b;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int main()
{
  int64_t n ;
  cin >> n ;

  auto count_digit = [](auto x)
  {
    std::string a = to_string(x) ;
    return a.size() ;
  };

  int64_t answer = 1000000000 ; 
  for(int i = 1 ; i <= sqrt(n) ; i++)
  {
    int64_t calcu = n / i ;
    if(i * calcu == n )
    {
      int64_t a = count_digit(i);
      int64_t b = count_digit(calcu);
      answer = min( answer, max( a , b ) ) ;
    }
  }

  cout << answer << endl;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = 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 CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
int a[125252];

int main(){
    scanf("%d%d",&n,&m);
    REP(i,n)scanf("%d",a+i);
    ll l = 1;
    REP(i,n){
        l = l * a[i] / __gcd(l, (ll)a[i]);
        if(l >= 2'000'000'000){
            puts("0"); return 0;
        }
    }
    REP(i,n){
        ll v = l / a[i];
        if(v%2==0){
            puts("0"); return 0;
        }
    }
    ll x = l/2;
    ll ans = m/x - m/l;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define forep(i, a, b) for(int64_t i=(a);i<(b);++i)
#define all(obj) (obj).begin(), (obj).end()
#define in(x) cin >> (x)
#define out(y) cout << (y) << "\n"
#define i64 int64_t
#define str string
using namespace std;
void Main() {
	/*----------------------------------------------------------------------------------------------------*/
	i64 N; in(N);
	str S; in(S);
	
	if (S.size() % 2 == 1) {
		out("No");
		return;
	}

	i64 count = 0;
	str buf;

	rep(i, N/2)
	{
		buf.push_back(S[i]);
		if (buf[i] == S[i + N / 2]) count++;
	}

	if (count == N / 2) out("Yes");
	else out("No");
	
	/*----------------------------------------------------------------------------------------------------*/
}
int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

s = list(map(int, list(ns())))
n = len(s)
l = [0]*(n+1)
t = 1
for i in range(n-1, -1, -1):
    l[i] = (l[i+1] + s[i]*t) % 2019
    t = t * 10 % 2019
d = Counter(l)
print(sum(y*(y-1)//2 for y in d.values()))


Measured memory_bytes: 18056
#include <iostream>
using namespace std;
int main(void){
	long long n,d,i,x,y,ans = 0;
	cin >> n >> d;
	for (i=0;i<n;i++) {
		cin >> x >> y;
		if ((x*x)+(y*y) <= (d*d)) {
			ans++;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int k = Integer.parseInt(in[1]);

        System.out.println(k > 1? n - k : 0);
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <cmath>

int main (void) {
  long long A = 0, B = 0, C = 0;
  std::cin >> A >> B >> C;
  
  long long MAX_len = 0; //ABC
  long long len1, len2 = 0;
  if(A >= B && A >= C) {
    MAX_len = A;
    len1 = B;
    len2 = C;
  } else if(B >= A && B >= C) {
    MAX_len = B;
    len1 = A;
    len2 = C;
  } else {
    MAX_len = C;
    len1 = A;
    len2 = B;    
  }
  
  long long len3_1 = 0, len3_2 = 0;
  len3_1 = std::floor(MAX_len / 2);
  len3_2 = MAX_len - len3_1;
  
  std::cout << (len3_2 - len3_1) * len1 * len2 << std::endl;
  
  return 0;    
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define st first
#define nd second
#define KW(a) ((a)*(a))
using namespace std;
 
const int maxN = 1 << 9;
const long long INF = 1000000000000000ll;

int T[maxN];
long long dp[maxN][maxN];

void solve()
{
	int n, k;
	scanf ("%d%d", &n, &k);
	FOR(i, 1, n+1)
		scanf ("%d", T+i);
	FOR(j, 1, k+1)
		dp[0][j] = INF;
	FOR(i, 1, n+2) FOR(j, 0, k+1)
	{
		dp[i][j] = INF;
		FOR(m, 0, min(j+1, i))
			dp[i][j] = min(dp[i][j], dp[i-m-1][j-m] + max(0, T[i] - T[i-m-1]));
	}
	
	printf("%lld\n", dp[n+1][k]);
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}



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

using namespace std;

int main() {
	int n, m;
	bool Use[10];
	for (int i = 0; i < 10; ++i) {
		Use[i] = true;
	}
	scanf("%d %d", &n, &m);
	while (m--) {
		int aux;
		scanf("%d", &aux);
		Use[aux] = false;
	}
	int ans = n;
	while (true) {
		int res = ans;
		while (res > 0) {
			int ok = res % 10;
			if (Use[ok]) {
				res /= 10;
			} else {
				break;
			}
		}
		if (res == 0) break;
		ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
	val input = IntArray(5) { (readLine() ?: return).toInt() }
	val dist = (readLine() ?: return).toInt()
	for (i in 0 until 5) for (j in i + 1 until 5) if (input[j] - input[i] > dist) {
		println(":(")
		return
	}
	println("Yay!")
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  int ans = k;
  rep(i, n) {
    int j = (i + n - 1) % n;
    int d = (i == 0 ? 0 : k) + a[j] - a[i];
    ans = min(ans, d);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a, b, c, d,cnt,n;
	while (cin >> n)
	{
		cnt = 0;
		for (a = 0; a < 10; a++)
			for (b = 0; b < 10; b++)
				for (c = 0; c < 10; c++)
					for (d = 0; d < 10; d++)
						if (a + b + c + d == n)
							cnt++;
		cout << cnt << endl;
	}
	return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
   int k,a,b; cin >> k >> a >> b;
   string ans = "NG\n";
   rep(i,a,b+1){
       if(i%k==0) ans = "OK\n";
   }
   cout << ans;
}

Measured memory_bytes: 3624
// https://atcoder.jp/contests/abc168/tasks/abc168_b

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;
#define lli long long int

int main()
{
    int k,l,i;
    char s[105];
    cin>>k;
    cin>>s;
    l=strlen(s);
    if(l<=k)
        printf("%s\n",s);
    else
    {
        for(i=0;i<k;i++)
            cout<<s[i];
        cout<<"..."<<"\n";
    }
    return 0;
}

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

using namespace std;



int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N, v[105];
  long long ans = 0;
  cin >> N;
  for (int i = 1; i <= N; ++i)
    cin >> v[i];
  sort (v + 1, v + N + 1);
  for (int i = 1; i <= N; ++i)
  for (int j = i + 1; j <= N; ++j)
  for (int k = j + 1; k <= N; ++k)
  if (v[i] != v[j] & v[j] != v[k] && v[i] != v[k] && v[i] + v[j] > v[k] && v[j] + v[k] > v[i] && v[i] + v[k] > v[j])
    ++ans;
  cout << ans;

}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl

signed main() {
  ios::sync_with_stdio(false);
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    int ans = abs(A[1] - A[0]);
    REP(i,N) {
      for(int j = i + 1; j < N; ++j) {
        ans = min(ans, abs(A[i] - A[j]));
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3112
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23252
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

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

ans = 0

# iが左からとる回数、jが右からとる回数
for i in range(K+1):
  for j in range(K+1-i):
    if i+j > N:
      break
    now = sorted(V[:i]+V[N-j:])
    tmp = min(K-i-j,bisect.bisect_left(now, 0))
    ans = max(ans,sum(now[tmp:]))

print(ans)


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

int main() {
    int n;
    cin >> n;
    ll ans=0;

    for (int i = 1; i <= n; i++) {
        if (i % 15 == 0 || i % 3 == 0 || i % 5 == 0) continue;
        else ans +=i;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3628
# coding: utf-8
# Your code here!

while True:
    a,b = [int(i) for i in input().split()]
    if a == 0 and b == 0:
        break
    
    if a < b:
        a, b = b, a
    
    c = 0
    while b > 0:
        a, b = b, a % b
        c += 1
    
    print(a, c)


Measured memory_bytes: 5616