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

public class Main {

    private static final int MAX = 51;
    private static final int INF = 1000000;
    
    private static final int[] dx = {1, 0, -1, 0};
    private static final int[] dy = {0, 1, 0, -1};

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

        int h, w;
        h = scanner.nextInt();
        w = scanner.nextInt();

        String[] s = new String[h];
        for (int i = 0; i < h; i++) {
            s[i] = scanner.next();
        }
        
        int[][] dist = new int[h][w];
        bfs(dist, s);
        if (dist[h - 1][w - 1] == INF) {
            System.out.println(-1);
            System.exit(0);
        }

        int[] count = new int[h * w + 1];
        int infCount = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (dist[i][j] == INF) {
                    infCount++;
                } else {
                    count[dist[i][j]]++;
                }
            }
        }
        int blackCount = countBlackGrid(s);
        int answer = infCount - blackCount;
        for (int i = 1; i <= h * w; i++) {
            if (i > dist[h - 1][w - 1]) {
                answer += count[i];
            } else {
                answer += count[i] - 1;
            }
        }
        System.out.println(answer);
    }

    private static void bfs(int[][] dist, String[] s) {
        Queue<Pair> queue = new ArrayDeque<Pair>();
        int h = dist.length;
        int w = dist[0].length;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                dist[i][j] = INF;
            }
        }
        queue.add(new Pair(0, 0));
        dist[0][0] = 0;
        
        while (!queue.isEmpty()) {
            Pair p = queue.remove();
            for (int i = 0; i < 4; i++) {
                int nextX = p.getFirst() + dx[i];
                int nextY = p.getSecond() + dy[i];
                if (isInGrid(nextX, nextY, h, w) && s[nextX].charAt(nextY) == '.' && dist[nextX][nextY] == INF) {
                    queue.add(new Pair(nextX, nextY));
                    dist[nextX][nextY] = dist[p.getFirst()][p.getSecond()] + 1;
                }
            }
        }
    }

    private static boolean isInGrid(int x, int y, int h, int w) {
        return 0 <= x && x < h && 0 <= y && y < w;
    }

    private static int countBlackGrid(String[] s) {
        int count = 0;
        for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length(); j++) {
                if (s[i].charAt(j) == '#') {
                    count++;
                }
            }
        }
        return count;
    }
}

class Pair {
    private final int first, second;

    public Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }

    public int getFirst() {
        return this.first;
    }

    public int getSecond() {
        return this.second;
    }
}


Measured memory_bytes: 21716
var h,hs = 0;

function insert(key){
    h[++hs] = key;

    var i = hs;

    while(h[i] > h[Math.floor(i / 2)]){
        var ex = h[i];
        h[i] = h[Math.floor(i / 2)];
        h[Math.floor(i / 2)] = ex;
        i = Math.floor(i / 2);
    }
}

function extract(){
    if(hs <= 0)
        return;

    var ret = h[1];

    h[1] = h[hs--];

    i = 1;
    while((i * 2 <= hs && h[i] < h[i * 2]) || (i * 2 + 1 <= hs && h[i] < h[i * 2 + 1])){
        var l = i * 2;var r = i * 2;
        if(i * 2 + 1 <= hs)
            r++;
        var m = h[l] > h[r] ? l : r;
        var ex = h[i];
        h[i] = h[m];
        h[m] = ex;
        i = m;

    }
    return ret;
}



function Main(input){
    input = input.split("\n");
    h = new Array(2000000001);h[0] == 2000000001;

    var i = 0;
    while(1){
        if(input[i].charAt(0) == "i"){
            input[i] = input[i].split(" ");
            insert(parseInt(input[i][1],10));
        }else if(input[i].charAt(1) == "x"){
           console.log(extract());
        }else{
            break;
        }
        i++;

    }
}
 
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 322604
#include<iostream>
#include<stack>
 
int main()
{
    std::stack<int> s;
    int x;
    while( std::cin >> x ){
        if( x ) s.push( x );
        else{
            std::cout << s.top() << std::endl;
            s.pop();
        }
    }
 
    return 0;
}

Measured memory_bytes: 1200
s = str(input())
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
flag = True

for i in range(len(s)):

    if i%2==1:
        if s[i] not in even:
            flag = False
            break

    elif i%2==0:
        if s[i] not in odd:
            flag = False
            break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        
        
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            int N = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split();

            long ans = s.Distinct().Count();
            Console.WriteLine(ans == 3 ? "Three" : "Four");
            //Console.Out.Flush();

        }

        
    }

    public class Calculation
    {

    }

    public class Graph
    {
        
    }
}




Measured memory_bytes: 13280
using System;
using System.Collections.Generic;
class AtCoder
{
    static void Main(string[] args)
    {
        var str = Console.ReadLine();
        Console.ReadLine();

        LinkedList<char> stringList = new LinkedList<char>();
        for( var i = 0; i < str.Length; i++)
        {
            stringList.AddLast(str[i]);
        }

        string line;
        bool reverse = false;
        while ((line = Console.ReadLine()) != null)
        {
            var spl = line.Split(' ');

            if (spl[0] == "1")
            {
                reverse = !reverse;
            }
            else
            {
                if (spl[1] == (reverse ? "2" : "1"))
                {
                    stringList.AddFirst(spl[2][0]);
                }
                else
                {
                    stringList.AddLast(spl[2][0]);
                }
            }
        }

        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        if (reverse)
        {
            var n = stringList.Last;
            do
            {
                Console.Write(n.Value);
                n = n.Previous;
            } while (n != null);
        }
        else
        {
            var n = stringList.First;
            do
            {
                Console.Write(n.Value);
                n = n.Next;
            } while (n != null);
        }
        Console.Out.Flush();
    }
}

Measured memory_bytes: 31524
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
using ll = long long;
const int N = 2e5+10;
ll cnts[N];
ll n;
int main() {
    memset(cnts, 0, sizeof cnts);
    cin >> n;
    int a;
    for(int i = 1; i < n; i ++) {
        cin >> a;
        cnts[a] ++;
    }
    for(int i = 1; i <= n; i ++) {
        cout << cnts[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int> keys;
	while(n--){
		int buf;
		cin >> buf;
		keys.push_back(buf);
	}
	
	for(int i = 1; i <= keys.size(); i++){
		cout << "node " << i << ": key = " << keys[i-1] << ", ";
		if(i/2 > 0) cout << "parent key = " << keys[i/2-1] << ", ";
		if(i*2 <= keys.size()) cout << "left key = " << keys[i*2-1] << ", ";
		if(i*2+1 <= keys.size()) cout << "right key = " << keys[i*2] << ", ";
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
 
template<class T> bool uin(T &a, T b) {return (a < b ? false : (a = b, true));}
template<class T> bool uax(T &a, T b) {return (a > b ? false : (a = b, true));}
 
//~ ifstream f(".in");
//~ ofstream g(".out");
 
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
}

int popcount(int x) {
  int ret = 0;
  while (x) {
    ++ret;
    x -= (x & (-x));
  }
  return ret;
}
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen(".in", "r", stdin);
#endif
 
  int n;
  cin >> n;
  vector<vector<bool>> a(n + 2, vector<bool>(n + 2));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      int x;
      cin >> x;
      a[i][j] = x;
    }
  }

  vector<int> dp((1 << n));
  dp[0] = 1;
  for (int mask = 0; mask < (1 << n); ++mask) {
    int man = popcount(mask) + 1;
    for (int j = 1; j <= n; ++j) {
      if (!(mask & (1 << (j - 1))) && a[man][j]) {
        add(dp[(mask ^ (1 << (j - 1)))], dp[mask]);
      }
    }
  }
  
  cout << dp[(1 << n) - 1] << '\n';
 
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 8448
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String op = sc.next();
    int b = sc.nextInt();
    if (op.equals("+")){
      System.out.println( a + b );
    }
    if (op.equals("-")){
      System.out.println(a-b);
    }
  }
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

void possible() {
	cout << "Possible" << endl;
	exit(0);
}

void impossible() {
	cout << "Impossible" << endl;
	exit(0);
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n;

	cin >> n;
	vector<int> a(n);
	vector<int> f(n, 0);
	REPU(i, 0, n) {
		cin >> a[i];
		f[a[i]]++;
	}
	sort(ALL(a));
	int mx = a.back();
	int hmx = (mx + 1) >> 1;
	if (a[0] == hmx) {
		if (f[hmx] != 1 + (mx % 2)) impossible();
		REPD(i, n - 1, hmx) if (f[i] > 0) {
			REPU(j, hmx + 1, i) if (f[j] == 0) {
				impossible();
			}
		}
		possible();
	}
	else impossible();

	return 0;
}


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

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

int N;
int A[100010];
bool ex_zero;
int neg_n;

signed main()
{
    cin >> N;
    rep(i, N)
    {
        cin >> A[i];
        if(A[i] == 0)ex_zero = true;
        if(A[i] < 0)neg_n++;
    }

    int ans = 0;
    
    if(ex_zero || neg_n % 2 == 0)
    {
        rep(i, N) ans += abs(A[i]);
        cout << ans << endl;
        return 0;
    }

    rep(i, N) A[i] = abs(A[i]);
    sort(A, A + N);
    rep(i,N)
    {
        if(i == 0)ans -= A[i];
        else ans += A[i];
    }

    cout << ans << endl;
    return 0;
}

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

void reconstruction(const vector<int>& pre, const vector<int>& in, 
                    vector<int>& post, int left, int right){
    if(left >= right){
        return;
    }
    static int position = 0;    // 再帰中でも順番に取り出すためにstatic
    int value = pre[position++];
    int middle = distance(in.begin(), find(in.begin(), in.end(), value));
    reconstruction(pre, in, post, left, middle);
    reconstruction(pre, in, post, middle+1, right);
    post.push_back(value);  // 後行順巡回なので最後に値を追加する
}

int main(){

    int n;
    cin >> n;
    
    vector<int> pre(n), in(n);
    // 先行順巡回
    for(int i = 0; i < n; ++i){
        cin >> pre[i];
    }
    // 中間順巡回
    for(int i = 0; i < n; ++i){
        cin >> in[i];
    }

    vector<int> post;   // 後行順巡回を入れるため配列

    reconstruction(pre, in, post, 0, n);

    for(int i = 0; i < n; ++i){
        if(i){
            cout << " ";
        }
        cout << post[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3164
import sys

def check(h, a, b, x):
    tot = 0
    for _ in h:
        if _ - x * b <= 0:
            continue
        tot +=  (_ - x * b + a - b - 1) // (a - b)

    return tot <= x
        
    

inp = map(int, sys.stdin.read().split())
n, a, b, *h = inp

l, r = 0, 10 ** 10
while l <= r:
    m = l + r >> 1
    if (check(h, a, b, m)):
        r, ans = m - 1, m
    else:
        l = m + 1

print(ans)

Measured memory_bytes: 14092
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        boolean flag = false;

        for (int i = a; i <= b; i++) {
            if (i % k == 0) {
                flag =true;
                break;
            }
        }

        if (flag) {
            System.out.println("OK");    
        } else {
            System.out.println("NG");            
        }

    }
}


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

int main() {
    int n; scanf("%d", &n);
    string a = "";
    for (int i = 0; i < n; ++i) {
        char tmp[4] = ""; scanf("%s", tmp);
        a += tmp;
    }
    
    int m; scanf("%d", &m);
    string b = "";
    for (int i = 0; i < m; ++i) {
        char tmp[4] = ""; scanf("%s", tmp);
        b += tmp;
    }
    
    if (a < b) printf("%d\n", 1);
    else printf("%d\n", 0);
    
    return 0;
}


Measured memory_bytes: 3340
from collections import deque
import sys

dlist = deque()

func = {'insert':dlist.appendleft, 'delete':dlist.remove, 'deleteFirst':dlist.popleft, 'deleteLast':dlist.pop}

n = int(sys.stdin.readline())

for line in sys.stdin:
    command = line.split()
    if len(command) == 2:
        command[1] = int(command[1])
    try:
        func[command[0]](*command[1:])
    except ValueError:
        pass

print(*dlist)

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

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  char s;
  char a;
  char *p;
  cin >> s;
  p = &a;
  if (isupper(s)) {
    cout << 'A' << endl;
  } else {
    cout << 'a' << endl;
  }
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  FDS(i,n){
    cin>>a[i];
  }
  int t;
  FDS(i,n){
    if(a[t]==2){
      cout<<i+1<<endl;
      return 0;
    }
    t=a[t]-1;
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 640
n=int(input())
d={}
drev={}
a=["A","C","G","T"]
judge=["AGC","ACG","GAC"]
ans=[[1 for i in range(61)]]+[[0 for i in range(61)] for j in range(n-3)]
cnt=0
mod=10**9+7
for i in range(4):
    for j in range(4):
        for k in range(4):
            s=a[i]+a[j]+a[k]
            if s == "AGC" or s =="ACG" or s == "GAC":continue
            d[s]=cnt
            drev[cnt]=s
            cnt+=1
for i in range(1,n-2):
    for j in range(61):
        for k in range(4):
            h=drev[j]+a[k]
            if h[1:] in judge or h[0]+h[2:]=="AGC" or h[:2]+h[3]=="AGC":continue
            ans[i][d[h[1:]]]+=ans[i-1][j]
            ans[i][d[h[1:]]]%=mod
print(sum(ans[-1])%mod)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
using namespace std;

const double pi = acos(1.0);
const int N = 3010;
int dp[N][N];
const int mod = 998244353;

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

int main()
{
	int n, m, nn, mm;
	cin >> n >> m >> nn >> mm;
    dp[n][m] = 1;
	for (int i = n; i <= nn; i++)
		for (int j = m; j <= mm; j++) {
			if (i == n && j == m) continue;
			add(dp[i][j], 1LL * dp[i - 1][j] * j % mod);
			add(dp[i][j], 1LL * dp[i][j - 1] * i % mod);
			add(dp[i][j], -1LL * dp[i - 1][j - 1] * (i - 1) % mod * (j - 1) % mod);
		}

	cout << dp[nn][mm] << endl;
	return 0;
}


Measured memory_bytes: 38328
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MAX 300005
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n,a[MAX],b[MAX];
bool check(int l,int r)
{
	int lstl=0,lstr=0;
	for(int i=l;i<=r;i++)
	{
		if(a[i]<l||a[i]>r) return false;
		if(a[i]<i)
		{
			if(a[i]<lstl) return false;
			lstl=a[i];
		}
		else if(a[i]>i)
		{
			if(a[i]<lstr) return false;
			lstr=a[i];
		}
	}
	return true;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),b[i]=(a[i]==i);
	for(int i=3;i<=n;i++)
		if(!b[i-2]&&!b[i-1]&&!b[i])
			return puts("No"),0;
	for(int i=1;i<=n;i++)
		if(!b[i])
		{
			int r=i;
			while(r<n&&b[r+1]==((r-i+1)&1))
				r++;
			if(!check(i,r))
				return puts("No"),0;
			i=r;
		}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 5940
#include <stdio.h>

int main(void) {
	int N, A;
	scanf("%d%d", &N, &A);

	int flag = 0;
	for (int i = 0;i <= A;i++) {
		if (N <= A || (N - i) % 500 == 0) {
			flag = 1;
			break;
		}
	}

	if (flag == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

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

int findSumOfDigits(int n)
{
  int sum = 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return(sum);
}

int main()
{
  int N;
  cin >> N;
  int sum = findSumOfDigits(N);
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int d;
	d=a+b;
	if((a%3)==0 || (b%3)==0 || (d%3)==0){
		cout<<"Possible"<<endl;
	}else{
		cout<<"Impossible"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	char a[3];
	int  d[3]={1,0,0};

	while(cin>>a){
        if(a[0]=='A'){
            if(a[2]=='B')swap(d[0],d[1]);
            else if(a[2]=='C')swap(d[0],d[2]);
        }
        else if(a[0]=='B'){
            if(a[2]=='A')swap(d[1],d[0]);
            else if(a[2]=='C')swap(d[1],d[2]);
        }
        else if(a[0]=='C'){
            if(a[2]=='B')swap(d[2],d[1]);
            else if(a[2]=='A')swap(d[2],d[0]);
        }


	}
	if(d[0]==1)cout<<'A'<<endl;
	else if(d[1]==1)cout<<'B'<<endl;
	else if(d[2]==1)cout<<'C'<<endl;


	return 0;
}

Measured memory_bytes: 1132
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = float("inf")
 
for i in range(2**n):
    highest = a[0]
    color = 1
    money = 0
    for j in range(1,n):
        if a[j] > highest:
            color += 1
            highest = a[j]
        elif (i>>j)&1:
            color += 1
            highest = highest + 1
            money += highest - a[j]
        
    if color >= k:
        ans = min(ans,money)
print(ans)

Measured memory_bytes: 3064
#include <functional>
#include <list>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <deque>
#include <stack>
#include <cassert>
using namespace std;
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define ALL(x) (x).begin(),(x).end()
#define CASET2 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0)
#define CASET1 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0)
#define CASET int ___T; scanf("%d ", &___T); while (___T-- > 0)
#define SZ(X) ((int)(X).size())
#define LEN(X) strlen(X)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
#define REPL(i,x) for(int i=0;x[i];i++)
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
#define RI1(x) scanf("%d",&x)
#define RI2(x,y) RI1(x), RI1(y)
#define RI3(x,y...) RI1(x), RI2(y)
#define RI4(x,y...) RI1(x), RI3(y)
#define RI5(x,y...) RI1(x), RI4(y)
#define RI6(x,y...) RI1(x), RI5(y)
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv)
#define DRI(argv...) int argv;RI(argv)
#define WRI(argv...) while (RI(argv) != EOF)
#define DWRI(x...) int x; WRI(x)
#define RS(x) scanf("%s",x)
#define MP make_pair
#define PB push_back
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define X first
#define Y second
#define V(x) vector<x >

typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int INF = 1000000000;

void print(int i) { printf("%d", i); }
template<class T> void PI(T i) { print(i); puts(""); }
template<class T> void PIS(T i) { print(i); printf(" "); }

template<class T>
void PV(T const &v, int N) {
    REP(i, N) {
        print(v[i]);
        printf("%c", i == N-1 ? '\n' : ' ');
    }
}

template<class T> void PV(T const &v) { PV(v, SZ(v)); }

template<class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; }
long long shift(int i) { return 1ll << i; }

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
int popcount(int x) { return __builtin_popcount(x); } 
int popcount(long long x) { return __builtin_popcountll(x); } 

#include <unordered_set>
#include <unordered_map>
#define EB emplace_back
#define RL(x) scanf("%lld", &(x))
#define PL(x) printf("%lld\n", x)
#define DRL(x) LL x; RL(x)

char a[10][10];
int main() {
  DRI(H, W);
  REP(i, H) {
    RS(a[i]);
  }
  int i = 0, j = 0;
  while (i != H-1 || j != W-1) {
    a[i][j] = '.';
    if (i+1 < H && a[i+1][j] == '#') {
      i++;
    } else if (j+1 < W && a[i][j+1] == '#') {
      j++;
    } else {
      puts("Impossible");
      return 0;
    }
  }
  a[i][j] = '.';
  REP(x, H) REP(y, W) {
    if (a[x][y] == '#') {
      puts("Impossible");
      return 0;
    }
  }
  puts("Possible");
  return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
//using atcorder.DataStructure;
namespace atcorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            atcorder.Test.Run();
        }
    }


    public class Test
    {
        public static void Run()
        {
            List<int> antena = new List<int>();
            for (int i = 0; i < 5; i++)
            {
                antena.Add(int.Parse(Console.ReadLine()));
            }
            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < 5; i++)
            {
                for (int j = i; j < 5;j++)
                if(antena[j]-antena[i]>k){
                    Console.WriteLine(":(");
                    return;
                }
            }
            Console.WriteLine("Yay!");
        }
    }




    public class Input
    {
        int arg;
        int length;
        string s;
        string[] ss;
        char sep;
        public Input(char _sep = '\0')
        {
            sep = _sep;
        }
        public void ReadLine()
        {
            s = Console.ReadLine();
            if (sep != '\0') ss = s.Split(sep);
            else
            {
                ss = new string[1];
                ss[0] = s;
            }
            arg = 0;
            length = ss.Length;
        }
        public T Next<T>()
        {
            if (arg == length) throw new IndexOutOfRangeException();
            return (T)Convert.ChangeType(ss[arg++], typeof(T));
        }
        public void SetSeparater(char _sep)
        {
            sep = _sep;
        }
    }
}


Measured memory_bytes: 11092
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A -= 1;
    B -= 1;
    C -= 1;
    D -= 1;
    string S;
    cin >> S;
    S += "#################";
    for(int i = A; i < max(C, D); i++){
        if(S[i] == '#' && S[i + 1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }
    if(C < D){
        cout << "Yes" << endl;
        return 0;
    }
    bool flag = false;
    for(int i = B - 1; i <= D - 1; i++){
        if(S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.'){
            flag = true;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() 
{
	ll n,m;
	cin>>n>>m;
	ll x[m],y[m];
	ll a,b,c;
	for(ll i=0;i<m;i++)
	{
		cin>>x[i]>>b;
		a=0;
		for(ll j=0;j<b;j++)
		{
			cin>>c;
			c--;
			a|=(1<<c);
		}
		y[i]=a;
	}
	ll N=pow(2,n);
	ll ans[N];
	ans[0]=0;
	for(ll i=1;i<N;i++)
	{
		ans[i]=10000000000000000;
	}
	for(ll i=0;i<N;i++)
	{
		for(ll j=0;j<m;j++)
		{
			a=i|y[j];
			ans[a]=min(ans[a],ans[i]+x[j]);
		}
	}
	if(ans[N-1]==10000000000000000)
	cout<<-1;
	else
	cout<<ans[N-1];
}

Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;

int main(){
    int n,m,q;
    int x,y;
    cin >> n >> m >> q;
    vector<int> stc((n+2)*(n+2) + 1);
    for (int i = 0; i<(n+2)*(n+2) + 1; i++) stc[i] = 0;
    for (int i = 0; i<m; i++){
        cin >> x >> y;
        for (int j = y; j<=n; j++){
            stc[1+n*j]++;
            stc[x+1+n*j]--;
        }
    }
    for (int i = 0; i<(n+2)*(n+2); i++) stc[i+1]+=stc[i];
    int p,s;
    for (int i = 0; i<q; i++){
        cin >> p >> s;
        cout << stc[p+n*s] << endl;
    }
}



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

int main()
{
	cout << fixed << setprecision(7);
	int n, w;
	while (cin >> n >> w, n || w) {
		double res = 0.01;
		vector<int> inter(20, 0);
		for (int i = 0, v; i < n; i++) {
			cin >> v;
			inter[v / w]++;
		}
		while (inter.back() == 0) {
			inter.pop_back();
		}
		int maxi = -1;
		for (int i = 0; i < inter.size(); i++) {
			maxi = max(maxi, inter[i]);
		}
		for (int i = 0; i < inter.size(); i++) {
			res += (double)inter[i] / maxi * (inter.size() >= 2 ? (double)(inter.size() - i - 1) / (inter.size() - 1) : 1.0);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int h;
  while(cin >> s){
    for(int i=0;i<s.size();i++){
      if(s[i]=='@'){
	h = s[i+1] - '0';
	for(int j=0;j<h;j++) cout << s[i+2];
	i += 2;
      }
      else cout << s[i];
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	long long n, d, count = 0;
	cin >> n >> d;
	for(int i = 0; i < n; ++i){
		long long a, b;
		cin >> a >> b;
		if(a * a + b * b <= d * d){
			count++;
			}
		}
	cout << count;
	return 0;
}


Measured memory_bytes: 3596
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if (a == 0)
		cout << 1;
	else if (b == 0)
		cout << 2;
	else if (c == 0)
		cout << 3;
	else if (d == 0)
		cout << 4;
	else
		cout << 5;
}


Measured memory_bytes: 3576
import itertools
N = int(input())
L = list(map(int,input().split()))
count=0
p_list=list(itertools.combinations(range(N),3))
for i in p_list:
    if((L[i[0]]!=L[i[1]]) and (L[i[2]]!=L[i[1]]) and (L[i[0]]!=L[i[2]]) ):
        if((L[i[0]]+L[i[1]]> L[i[2]]) and (L[i[1]]+L[i[2]]> L[i[0]]) and (L[i[0]]+L[i[2]]> L[i[1]])):
            count+=1
print(count)

Measured memory_bytes: 20620
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

char s[111];

int main(void) {
  scanf("%s", s);
  string a = s;
  if (a.size() >= 4 && a.substr(0, 4) == "YAKI") puts("Yes"); else puts("No");
  return 0;
}


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

constexpr int lim = 100000;
char isprime[lim];
int prime[lim];
int ind = 0;

void set_prime() {
    fill(isprime, isprime + lim, 1);
    isprime[0] = isprime[1] = 0;

    for (int x = 2; x < lim; ++x) {
        if (!isprime[x]) continue;
        prime[ind++] = x;

        if (x * 2 >= lim) continue;
        for (int y = x * 2; y <  lim; y += x) {
            isprime[y] = 0;
        }
    }
}

pair<int, int> solve(const int& m, const int& a, const int& b) {
    int max_pq = 0;
    pair<int, int> ret;
    for (int j = 0; j < ind && prime[j] < m; ++j) {
        int q = prime[j];

        int* lb = lower_bound(prime, prime + ind, (double)a * q / b);

        int p = *(upper_bound(prime, prime + ind, min(q, m / q)) - 1);

        if(*lb <= p && p * q > max_pq) {
            max_pq = p * q;

            ret = make_pair(p, q);
        }
    }

    return ret;
}

int main() {
    set_prime();

    int m, a, b;
    while (true) {
        cin >> m >> a >> b;

        if(m == 0) break;
        pair<int, int> ret = solve(m, a, b);
        cout << ret.first << ' ' << ret.second << endl;
    }
    return 0;
}

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

int cmp(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int n, k;
    int h[200000];
    size_t i;
    unsigned long long s = 0;
    scanf("%d%d", &n, &k);
    if (n <= k)
    {
        printf("0\n");
        return 0;
    }
    for (i = 0; i < n; i++)
    {
        scanf("%d", &(h[i]));
    }
    qsort(h, n, sizeof(h[0]), cmp);

    for (i = 0; i < n-k; i++)
    {
        s += h[i];
    }

    printf("%llu\n", s);
    return 0;
}

Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys, math, fractions, itertools

def solve(N: int, A: int, x: "List[int]"):
    X = max(x)
    dp = [[[0 for _ in range(max(N*X+1, N*A+1))] for _ in range(N+1) ] for _ in range(N+1)]
    dp[0][0][0] = 1
    for n in range(N+1):
        for m in range(N+1):
            for k in range(N*X+1):
                if n >= 1 and k < x[n-1]:
                    dp[n][m][k] = dp[n-1][m][k]
                elif n >= 1 and m >= 1 and k >= x[n-1]:
                    dp[n][m][k] = dp[n-1][m][k] + dp[n-1][m-1][k-x[n-1]]
    s = 0
    for i in range(1, N+1):
        s += dp[N][i][i*A]
    print(s)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, x)

if __name__ == '__main__':
    main()


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

const int inf = -1000;
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a /gcd(a, b) *b;
}
int main() {



   int x,a;
   cin>>x>>a;
   if(x<a)
      cout<<"0";
   else
    cout<<"10";

    return 0;

      }


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

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"

#define ll long long
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll, ll> pll;
typedef map< ll, ll> mll;

#define pie_value 3.14159265358979323846

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n;
	cin >> n;

	if (n >= 30)
		cout << "Yes" << nl;
	else {
		cout << "No" << nl;
	}


	return 0;
}


Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var n, m, c int
	fmt.Scan(&n, &m, &c)

	b := make([]int, m)
	for i := range b {
		fmt.Scan(&b[i])
	}

	a := make([][]int, n)
	for i := range a {
		a[i] = make([]int, m)
		for j := range a[i] {
			fmt.Scan(&a[i][j])
		}
	}

	count := 0
	for i := 0; i < n; i++ {
		judge := 0
		for j := 0; j < m; j++ {
			judge += a[i][j] * b[j]
		}
		judge += c
		if judge > 0 {
			count++
		}
	}
	fmt.Println(count)
}


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

int main()
{
  int N;
  cin >> N;
  int ans = 0;
  int current = 1;
  for (int i = 0; i < N; i++)
  {
    int num;
    cin >> num;
    if (num != current)
    {
      ans++;
    }
    else
    {
      current++;
    }
  }
  if (ans == N)
  {
    ans = -1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define REPll(i,m,n) for(ll i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

ll count(ll a) {
	ll hoge = 0;
	while (a != 0) {
		hoge += a % 10;
		a /= 10;
	}
	return hoge;
}

int main() {
	ll n;
	cin >> n;
	ll ans = count(n);
	ll foo = 10;
	while (n != 0) {
		n -= (n%foo) + 1;
		foo *= 10;
		if (n < 0) {
			break;
		}
		ans = max(ans, count(n));
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    long long *a = new long long[n];

    long long max = 1000000001;

    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    while(1){
        sort(a, a+n);
        int flag = 0;
        for (int i=1;i<n;i++){
            if (a[i] < max){
                a[i] = a[i] % a[0];
                if (a[i] > 0){
                    flag++;
                }
                else{
                    a[i] = max;
                }
            }
        }
        if (flag==0){
            break;
        }
    }
    cout << a[0] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

const double eps=1e-10;
double add(double a,double b){
    if(abs(a+b)<eps*(abs(a)+abs(b)))return 0;
    return a+b;
}

typedef pair<double,double> P;
P operator+(const P& x,const P& y){
    return {add(x.first,y.first),add(x.second,y.second)};
}

P operator-(const P& x,const P& y){
    return {add(x.first,-y.first),add(x.second,-y.second)};

}

P operator*(const P& x,const double& y){
    return {x.first*y,x.second*y};
}
double dot(P x,P y){
    return add(x.first*y.first,x.second*y.second);


}

double det(P x,P y){
    return add(x.first*y.second,-x.second*y.first);
}

bool onseg(P p1,P p2,P q){
    return det(p1-q,p2-q)==0 &&dot(p1-q,p2-q)<=0; 
}

P intersection(P p1,P p2,P q1,P q2){
    return p1+(p2-p1)*(det(q2-q1,q1-p1)/det(q2-q1,p2-p1));
}

bool cross(P p1,P p2,P q1,P q2){
    if(det(p1-p2,q1-q2)==0)return onseg(p1,p2,q1)||onseg(p1,p2,q2)||onseg(q1,q2,p1)||onseg(q1,q2,p2);
    P ret=intersection(p1,p2,q1,q2);
    return onseg(p1,p2,ret)&&onseg(q1,q2,ret);
}

int main(){
    int n;
    cin>>n;
    rep(wrtwrt,n){
        P s,t;
        cin>>s.first>>s.second>>t.first>>t.second;
        int m;cin>>m;
        map<P,int> mp;
        vector<P> v;
        rep(i,m){
            P x,y;
            cin>>x.first>>x.second>>y.first>>y.second;
            int a,b;
            cin>>a>>b;
            if(cross(s,t,x,y)){
                mp[intersection(s,t,x,y)]=a^b;
                v.push_back(intersection(s,t,x,y));
                }
        }
        if(v.empty()){cout<<0<<endl;continue;}
        int ans=-1;
        int pos=-1;
        sort(v.begin(),v.end());
        rep(i,v.size()){
            if(mp[v[i]]!=pos)ans++;
            pos=mp[v[i]];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <math.h>

unsigned long long gcd(unsigned long long a,unsigned long long b)
{
    if(b==0)
    {
        return a;
    }
    else
    {
        return gcd(b,a%b);
    }
}
int main()
{
    unsigned long long a,b,c,d,x,y,z,p,q,r,i,j,k;

    scanf("%llu %llu %llu %llu",&a,&b,&c,&d);

    x=gcd(c,d);
    y=(c*d)/x;
    p=(b/c)-((a-1)/c);
    q=(b/d)-((a-1)/d);
    r=(b/y)-((a-1)/y);

    j=b-a+1;
    z=j-p-q+r;
    printf("%llu",z);

}


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

int main(){
  string S;
  int a,m = 753;
  cin>>S;
  
  for(int i=0;i<S.size()-2;i++){
    a = stoi(S.substr(i,3));
    m = min(m,abs(753-a));
  }
  
  cout<<m<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n;
 	cin>>n;
 	ll temp=n;
 	ll ans=0;
 	for(ll i=2;i*i<=n;i++)
 	{
 		 if(temp%i > 0)continue;
 		ll cnt=0;
 		while(temp%i==0)
 		{
 			++cnt;
 			temp/=i;
 		}
 		// cout<<temp<<endl;
 		// cout<<i<<" "<<cnt<<endl;
 		ll cur=0;
 		ll l=1,r=cnt;
 		while(l<=r)
 		{
 			ll mid=(l+r)/2;
 			ll val = ((mid)*(mid+1))/2;
 			if(val>cnt)
 			{
 				r=mid-1;
 			}
 			else
 			{
 				cur=max(cur,mid);
 				l=mid+1;
 			}
 		}
 		ans+=cur;
 	}
 	if(temp>1)
 	{
 		ans++;
 	}
 	cout<<ans<<endl;
    return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int a = 0;
  for(int i=0; i<n; i++){
    int t = 0;
    for(int j = 0; j<n-i; j++){
      t = (t+1)*(s[j]==s[j+i]);
      a = max(a, min(t,i));
    }
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int ans = 0;
		if (A<=B){
			ans += A;
		}else{
			ans += B;
		}
		if (C<=D){
			ans += C;
		}else{
			ans += D;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 35632
// 12/07/2020  @ 19:54:17
// *****************************************************************
// *****************************************************************
#include <bits/stdc++.h>
// *****************************************************************
// *****************************************************************
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#define fr(i,n) for(llu i=0;i<n;i++)
#define fl(j,a,b) for(llu j=a;j<=b;j++)
#define Pi 3.1415926535897932384626
#define mod 1e9+7
#define MID(a,b) ((a + b) >> 1)
#define MAX(a,b) ((a) > (b) ? (a): (b))
#define MIN(a,b) ((a) < (b) ? (a) :(b))
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define printer(a, n) fr(i,n) cout << a[i] << " ";
// *****************************************************************
// *****************************************************************
typedef long long unsigned int llu;
typedef long long int ll;
// *****************************************************************
// *****************************************************************
using namespace std;
// *****************************************************************
// *****************************************************************

                   // Dream it. Wish it. Do it.

                         // tannatsri //

              // Without tact you can learn nothing.

// *****************************************************************
// *****************************************************************
bool rev(ll a, ll b) {
    return a > b;
}
// *****************************************************************
void solution() {
	ll n;
	cin >> n;
	cout << n + n * n + n *n* n;

}
// *****************************************************************
int main() {
    IOS;
    // #ifndef ONLINE_JUDGE
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/input.txt", "r", stdin);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/output.txt", "w", stdout);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/error.txt", "w", stderr);
    // #endif
    // *****************************************************************
    // *****************************************************************
    int t = 1;
    // cin >> t;
    while(t--) {

       solution();
       cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3592
n = int(input())
a = list(map(int, input().split()))
p = 10 ** 9 + 7

y = 0
for i in range(n):
    y += a[i]
    y = y % (2 * p)
x = (y ** 2) % (2 * p)

w = 0
for i in range(n):
    w += ((a[i] ** 2) % (2 * p))
    w = w % (2 * p)

z = ((x - w) / 2) % p
print(int(z))

Measured memory_bytes: 31556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define has(c,i) (c.find() != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

#define DBG 0
#define TR(X) ({ if(DBG) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

	string s;
	string t;
	cin >> s >> t;

	vvl dist(sz(s), vl(26, -1));
	// distance to first occurence from current position for given char -'a'

	FOR(foo,0,2){
		FORD(i,0,sz(s)){
			ll cur = s[i] - 'a';

			FOR(j,0,26) {
				if(dist[(i + 1) % sz(s)][j] < 0)
					continue;
				dist[i][j] = dist[(i + 1) % sz(s)][j] + 1;
			}

			dist[i][cur] = 0;
		}
	}

	ll cur = -1;

	for(const char c : t){
		ll next = cur + 1;
		if(dist[next % sz(s)][c - 'a'] == -1){
			cout << "-1" << endl;
			exit(0);
		}

		TR(cur);
		TR(c);
		TR(dist[next % sz(s)][c - 'a']);

		cur += dist[next % sz(s)][c - 'a'] + 1;
	}
	cout << cur  + 1 << endl;;
}


Measured memory_bytes: 24656
from collections import deque
from itertools import dropwhile

alphabet = set('abcdefghijklmnopqrstuvwxyz')

if __name__ == '__main__':
    s = input()
    l = [c for c in alphabet - set(s)]
    if l != []:
        print(s + min(l))
        quit(0)

    deq = deque()
    deq.append(s[-1])
    for i in range(24, -1, -1):
        if s[i] < s[i + 1]:
            small = next(dropwhile(lambda c: c <= s[i], deq))
            print(s[:i] + small)
            quit(0)
        else:
            deq.append(s[i])

    print(-1)





Measured memory_bytes: 3316