akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
static const int INFTY = (1 << 21);

class Edge{
public:
    int from, to, cost;
    Edge(int from = 0, int to = 0, int cost = 0) :
            from(from), to(to), cost(cost){}

    bool operator < (const Edge &e) const{
        return cost < e.cost;
    }
    bool operator >(const Edge &e) const{
        return cost > e.cost;
    }

};

class Node{
public:
    vector<Edge> edges;
    int dist;
    Node(){
        dist = INFTY;
    }
};

class Graph{
public:
    vector<Node> nodes;
    int cost;
    Graph(int n) {
        rep(i, n) { Node n;  nodes.push_back(n); }
        cost = 0;
    }
    Node& operator[](int i){
        return nodes[i];
    }
};

class Data{

public:
    int cost;
    Edge *edge;
    Data(int cost, Edge *edge) {
        this->cost = cost;
        this->edge = edge;
    }

    bool operator < (const Data &d) const{
        return cost < d.cost;
    }
    bool operator >(const Data &d) const{
        return cost > d.cost;
    }
};

Graph G(0);

int main() {

    int V, E;
    cin >> V >> E;
    G = Graph(V);

    rep(i, E){
        int from, to, cost;
        cin >> from >> to >> cost;
        G[from].edges.push_back(Edge(from, to, cost));
        G[to].edges.push_back(Edge(to, from, cost));
    }

    // prim
    priority_queue<Data, vector<Data>, greater<Data> > pq;
    Edge e0(-1, 0, 0);
    pq.push(Data(0, &e0));

    while (!pq.empty()){
        Data d = pq.top(); pq.pop();
        Edge& e = *d.edge;
        Node& n = G[e.to];
        if (n.dist != INFTY){ continue; }
        n.dist = 0;
        G.cost += e.cost;

        for (auto &ee : n.edges){
            Data d(ee.cost, &ee);
            pq.push(d);
        }
    }

    cout << G.cost << endl;

}

Measured memory_bytes: 11252
#include <bits/stdc++.h>
#define ll long long 
#define endl "\n"
using namespace std;

void solve()
{
	//Enter code here Tanmay::
	int a,b,c,count=1;
	cin>>a>>b;
	if(b==1)
	{
		cout<<"0";
		exit(0);
	}
	if(a>=b)
	{
		cout<<"1";
		exit(0);
	}
	
	while(true)
	{
		count++;
		c=c+(a-1);
		if((c+a)>=b)
		break;
		
	}
	cout<<count;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
void fastscan(int &number) 
{ 
    //variable to indicate sign of input number 
    bool negative = false; 
    register int c; 
  
    number = 0; 
  
    // extract current character from buffer 
    c = getchar(); 
    if (c=='-') 
    { 
        // number is negative 
        negative = true; 
  
        // extract the next character from the buffer 
        c = getchar(); 
    } 
  
    // Keep on extracting characters if they are integers 
    // i.e ASCII Value lies from '0'(48) to '9' (57) 
    for (; (c>47 && c<58); c=getchar()) 
        number = number *10 + c - 48; 
  
    // if scanned input has a negative sign, negate the 
    // value of the input number 
    if (negative) 
        number *= -1; 
} 

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

ll str_to_ll(string value){
  ll ans = 0LL;
  for (int i = 0; i < value.size(); i++) {
      ans *= 10;
      ans += (ll)(value[i] - '0');
  }
  return ans;
}

ll calc(string &S, vector<int> plus){
  ll result = 0LL;
  string word = "";
  word += S.at(0);
  for(int i=0; i< plus.size(); i++){
    if(plus.at(i) ==1){
      result += str_to_ll(word);
      word = S.at(i+1);
    }
    else{
       word += S.at(i+1);
    }
  } 
  result += str_to_ll(word);
  return result;
}
ll dfs(string &S, int cnt, vector<int> plus){
  if(cnt == plus.size()){
    return calc(S, plus);
  }
  ll ans = 0LL;
  ans += dfs(S, cnt+1, plus);
  plus.at(cnt) = 1LL;
  ans += dfs(S, cnt+1, plus);  
  return ans;
}

int main(){
  string S;
  cin >> S;
  vector<int> plus(S.size() - 1);
  ll ans = dfs(S, 0, plus);
  cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val a = readInputLine().split(" ").map { x -> Integer.parseInt(x) }
    if ((a[0] < a[2] && a[2] < a[1]) || 
        (a[0] > a[2] && a[2] > a[1])) {
        println("Yes")
    } else {
        println("No")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37908
from fractions  import gcd


n=int(input())
a=list(map(int,input().split()))
inf = 0
num_min =2**(n-1).bit_length()
dat=[inf]*(2*num_min-1)

#初期化
for i in range(n):
    dat[i+num_min-1]=a[i]
for i in range(num_min-2,-1,-1):
    dat[i]=gcd(dat[2*i+1],dat[2*i+2])

#親のノード(n-1)//2
#子のノード2n+1,2n+2

def segfunc(x,y):
    return gcd(x,y)

def update(i,x):
    i+=n-1
    dat[i]=x
    while i>0:
        i=(i-1)//2
        dat[i]=segfunc(dat[2*i+1],dat[2*i+2])
def query(a,b): #半開区間、[a,b)の最小値
    if b<=a:
        return inf
    res=inf
    a += num_min-1
    b += num_min-2
    while b-a>1:
        if a&1==0:
            res = segfunc(res,dat[a])
        if b&1==1:
            res = segfunc(res,dat[b])
            b-=1
        a=a//2
        b=(b-1)//2
    if a==b:
        res = segfunc(res,dat[a])
    else:
        res=segfunc(segfunc(res,dat[a]),dat[b])
    return res

ans=0
for i in range(n):
    left=query(0,i)
    right=query(i+1,n)
    ans=max(ans,gcd(left,right))
print(ans)

Measured memory_bytes: 95720
#include<cstdio>
#include<algorithm>
using namespace std;
int n,i,k;char c;long long f0,f1,f2;
int main(){
	scanf("%d%d",&n,&f0);
	for (f1=f2=-1e18,n--;n--;){
		scanf(" %c%d",&c,&k);
		if (c=='-') k=-k;
		long long v0=f0+k,v1=f1-k,v2=f2+k;
		f0=max(v0,max(v1,v2));
		if (c=='+') f1=max(v1,v2),f2=v2;
		else f1=max(v0,max(v1,v2)),f2=max(v1,v2);
	}
	printf("%lld",f0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int x;
    int y;
    cin >> x >> y;
    if(x%y == 0) {
        cout << -1 << endl;
    } else {
        cout << x << endl;
    }
}

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

using ll = long long;
ll dp[100001];
int arr[100001];
int n;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }
    dp[2] = abs(arr[1] - arr[2]);
    for(int i = 3; i <= n; i++){
        dp[i] = min(abs(arr[i - 2] - arr[i]) + dp[i - 2], abs(arr[i - 1] - arr[i]) + dp[i - 1]);  
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 4744
#include<stdio.h>

int main(){
    int i;
    char S[4];
    scanf("%s",&S);

    if(S[0]==S[1] && S[2]==S[3] && S[0]!=S[2])printf("Yes\n");
    else if(S[0]==S[2] && S[1]==S[3] && S[0]!=S[1])printf("Yes\n");
    else if(S[0]==S[3] && S[1]==S[2] && S[0]!=S[1])printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,P;
	cin >> N >> P;
	if(N == 1) {
		cout << P << endl;
	}
	else {
		int ret = 1;
		for(int i = 2;i * i <= P;i++) {
			int cnt = 0;
			while(P % i == 0) {
				cnt++;
				P = P / i;
			}
			if(cnt >= N) {
				ret *= pow(i,cnt / N);
			}
		}
		cout << ret << endl;
	}
}

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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n%2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	string a = s.substr(0, n/2);
	string b = s.substr(n/2, n/2);
	if (a == b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3520
#include <stdio.h>

int n;
int a, b, c, d;
char str[200005];

int check(int l, int r);
int space(int l, int r);

int main()
{
    int f = 0;
    
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    scanf("%s", str);

    --a; --b;
    
    // [a, c), [b, d)
    if (a <= b && d <= c) {
        if (check(a, c) && check(b, d) &&
            space(b, d)) {
            f = 1;
        }
    }
    else if (b <= a && c <= d) {
        if (check(a, c) && check(b, d) &&
            space(a, c)) {
            f = 1;
        }
    }
    else {
        if (check(a, c) && check(b, d)) {
            f = 1;
        }
    }

    puts(f ? "Yes" : "No");
    
     return 0;
}

int check(int l, int r)
{
    int res = 1;
    for (int i = l; i < r - 1; i++) {
        if (str[i] == '#' && str[i + 1] == '#') {
            res = 0;
        }
    }

    return res;
}

int space(int l, int r)
{
    int res = 0;

    for (int i = l; i < r; i++) {
        if (str[i - 1] == '.' && str[i] == '.' && str[i + 1] == '.') {
            res = 1;
        }
    }

    return res;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<numeric>
#include<list>
#include<cmath>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0])
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;



int main(void) {
	int n;
	ll D;
	int count = 0;
	cin >> n>>D;
	vector<ll> x(n),y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		if ((x[i] * x[i]) + (y[i] * y[i]) <= D * D) {
			count++;
		}

	}

	cout << count;

	return 0;
}


Measured memory_bytes: 6340
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  ll ans = 0, num = x;
  int cnt = 0;
  vector<int> a(m, -1);
  bool ok = true;
  for(int i = 0; i < n; i++) {
    ans += num;
    if(num == 0) {
      cout << ans << endl;
      return 0;
    }
    if(a[num] >= 0) {
      cnt = i;
      ok = false;
      break;
    }
    a[num] = i;
    num = num * num % m;
  }
  if(ok) {
    cout << ans << endl;
    return 0;
  }
  n -= a[num];
  int border = a[num];
  vector<ll> sum(m, 0);
  num = x;
  ans = 0;
  for(int i = 0; i < border; i++) {
    ans += num;
    num = num * num % m;
  }
  for(int i = 0; i < cnt - border + 1; i++) {
    sum[i + 1] += sum[i] + num;
    num = num * num % m;
  }
  ans += sum[cnt - border] * (n / (cnt - border));
  ans += sum[n % (cnt - border)];
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;
    cout << N*N*N << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProconTemplate
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_c
    class abc169_b
    {
        //private static int[] m_aiPrimes;
        //private static int m_iCurPrimeIdx;
        public static void Main(string[] args)
        {
            //string s = Console.ReadLine();
            //int[] xi = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            //string[] asInput = Console.ReadLine().Split(' ');
            //long A = long.Parse(asInput[0]);
            //decimal B = decimal.Parse(asInput[1]);
            //Console.WriteLine(A * (long)(100 * B) / 100);

            string[] asInput = Console.ReadLine().Split(' ');
            int X = int.Parse(asInput[0]);
            int N = int.Parse(asInput[1]);

            if (N == 0)
            {
                Console.ReadLine();
                Console.WriteLine(X);
                return;
            }
            int[] pn = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            for (int i = 0; i < 101; i++)
            {
                if (Array.IndexOf(pn, X - i) < 0)
                {
                    Console.WriteLine(X - i);
                    return;
                }

                if (Array.IndexOf(pn, X + i) < 0)
                {
                    Console.WriteLine(X + i);
                    return;
                }
            }


        }

    }
}


Measured memory_bytes: 28308
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
inline int read()
{
	char c=getchar(); int num=0,f=1;
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c<='9'&&c>='0') { num=num*10+c-'0'; c=getchar(); }
	return num*f;
}
int n,w[300005],e[300005],ans;
char s[300005];
int main()
{
	ans=n=read(); scanf("%s",s+1);
	for (int i=1;i<=n;i++) w[i]=w[i-1]+(s[i]=='W');
	for (int i=n;i>=1;i--)
	{
		e[i]=e[i+1]+(s[i]=='E');
		ans=min(ans,e[i+1]+w[i-1]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2944
N, M = map(int, input().split())
n_list = [[int(i) for i in input().split()] for i in range(N)] 
m_list = [[int(i) for i in input().split()] for i in range(M)] 

def cal_distance(x1, x2, y1, y2):
    return abs(x1 - x2) + abs(y1 - y2)

for n in n_list:
    distance = 10 ** 16
    ans = 0
    for i in range(len(m_list)):
        this_distance = cal_distance(n[0], m_list[i][0], n[1], m_list[i][1])
        if distance > this_distance:
            distance = this_distance
            ans = (i + 1)

    print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    used=[0]*N
    for i in range(K):
        d=I()
        A=LI()
        for j in range(d):
            used[A[j]-1]=1
            
    print(N-sum(used))
        
    

main()


Measured memory_bytes: 67564
#include<stdio.h>

int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a*b>c*d){
		printf("%d",a*b);

	}
	else if(a*b<c*d){
		printf("%d",c*d );
	}
	else{
		printf("%d",a*b);
	}




	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define lli                      int long long
#define ull                      unsigned long long
#define ld                       long double
#define pi                       acos(-1)
#define pb                       push_back
#define pbk                      pop_back
#define mp                       make_pair
#define all(v)                   v.begin(),v.end()
#define ff                       first
#define ss                       second
#define pii                      pair<int,int>
#define gcd(a,b)                 __gcd(a,b)
#define lcm(a,b)                (a/gcd(a,b))*b
#define READ                     freopen("in.txt","r",stdin);
#define WRITE                    freopen("outer.txt","w",stdout);
#define sort(t)                  sort(t.begin(),t.end())
#define mem(a,b)                 memset(a,b,sizeof a)
#define t_c(t)                          for(int z=1;z<=t;z++)
#define p_c                             printf("Case %d: ",z)
#define LINE_PRINT_CASE          printf("Case %d:\n",z)
#define sf                       scanf
#define pf                       printf
#define dist(ax,ay,bx,by)        sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define MX                       100005
#define inf                      10000000000000000+7
#define M                        1000000002
#define MINI                     -1000000003
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move

//int kx[]={+2,+2,-2,-2,+1,+1,-1,-1};     //Knights move
//int ky[]={+1,-1,+1,-1,+2,-2,+2,-2};     //Knights move


//#define for(i,a,n)    for(int i=a;i<n;i++)
//it=myset.find(20);
//int a[8]= {0,0,-1,1,-1,1,-1,1};
//int b[8]= {-1,1,0,0,-1,1,1  ,-1};

int main()
{
 lli n,i,j;
 cin>>n;
 lli a[n+5],b[n+5],c[n+5],ans=0;
 for(i=0;i<n-1;i++)cin>>a[i];
 for(i=0;i<n-2;i++)
 {
     ans+=min(a[i],a[i+1]);
 }
 ans+=a[0];
 ans+=a[n-2];
 cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  std::cin >> a>>b>>c;
  if(a==b)std::cout << c << std::endl;
  else if(a==c)std::cout << b << std::endl;
  else std::cout << a << std::endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    static String line;
    static int p;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            line = sc.next();
            p = 0;
            System.out.println(dfs());
        }
    }

    static int dfs() {
        ArrayList<Integer> points = new ArrayList<>();
        while (true) {
            if (p == line.length() || line.charAt(p) == ']') {
                break;
            }
            if (line.charAt(p) == '[') {
                p ++;
                points.add(dfs());
                p ++;
            } else {
                int n = 0;
                while ("1234567890".contains(line.charAt(p) + "")) {
                    n = n * 10 + Integer.parseInt(line.charAt(p) + "");
                    p ++;
                }
                return n / 2 + 1;
            }
        }
        Collections.sort(points);
        int sum = 0;
        for (int i = 0; i < points.size() / 2 + 1; i++) {
            sum += points.get(i);
        }
        return sum;
    }
}

Measured memory_bytes: 62868
import fractions

def get_lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = list(map(lambda x: int(x), a_str_list))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a += get_num(a, lcm)

result = lcm / sum_a
print(result)


Measured memory_bytes: 5368
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>

int main() {

	int c[10][10];
	int H, W;

	scanf("%d %d", &H, &W);
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			scanf("%d", &c[i][j]);
		}
	}

	int cost[10] = {};
	for (int i = 0; i < 10; i++) {
		int calc[10] = {};
		calc[i]++;
		for (int lc = 1;; lc++) {
			for (int p = 0; p < 10; p++) {
				for (int q = 0; q < 10; q++) {
					if (calc[p] == c[p][q] && calc[q] == 0 && calc[p] != 0) calc[q]=-1;
				}
			}
			if (calc[1] != 0) {
				cost[i] = lc;
				break;
			}
			for (int p = 0; p < 10; p++) {
				if (calc[p] > 0) calc[p]++;
				else if (calc[p] == -1) calc[p] = 1;
			}
		}
	}
	cost[1] = 0;

	int ans = 0;

	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			int a;
			scanf("%d", &a);
			if (a >= 0) ans += cost[a];
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, a[114];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int cnt = 1, ans = 0;
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cnt++;
		}
		else {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	ans += cnt / 2;
	cout << ans << endl;
	endre;
}

Measured memory_bytes: 256
#include<stdio.h>

#define ll long long

int main()
{
    int n,k,s;
    scanf("%d%d%d",&n,&k,&s);
    for(int i=1;i<=k;++i)
    {
        printf("%d",s);
        if(i<k)putchar(32);
    }
    if(k<n)putchar(32);
    if(s==1)s=4;
    for(int i=k+1;i<=n;++i)
    {
        printf("%d",s-1);
        if(i<n)putchar(32);
    }
    return 0;
}

Measured memory_bytes: 1280
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool calc(int a, int b) {
    for (int i = 0; i < (1 << 16); i++) {
        bool[] xs;
        for (int j = 0; j < 16; j++) {
            xs ~= (i & (1 << j)) == 0;
        }
        xs ~= xs[0];

        bool ok = true;
        int x = 0;
        int y = 0;
        for (int j = 0; j < xs.length - 1; j++) {
            if (xs[j]) x++; else y++;

            if (xs[j] == xs[j + 1]) {
                ok = false;
                break;
            }
        }

        if (ok) {
            if (x >= a && y >= b) return true;
            if (x >= b && y >= a) return true;
        }
    }
    return false;
}

void main() {
    auto ab = readints;
    int a = ab[0], b = ab[1];

    auto ans = calc(a, b);
    writeln(ans ? "Yay!" : ":(");
}

Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC127A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, x;

            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            x = int.Parse(word[1]);

            if (A >= 13)
                x = B;
            else if (6 <= A && 6 <= 12)
                x = B / 2;
            else if (A <= 5)
                x = 0;


            Console.WriteLine(x);
            Console.ReadKey();
             
               
                

        }
    }
}


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

char str[110];
int i,j,k,l,m,n;
int n,e,s,w,un,up;
int a[7],b[7], qu[25],qf[25],ufl[25];
int t;

void input() {
  for(i=0;i<6;i++){
    scanf("%d",&a[i+1]);
    b[i+1] = a[i+1];
    // printf("a[%d] = %d\n",i+1,a[i+1]);
  }

  scanf("%d",&n);
  //printf("n = %d\n",n);

  for(i=0;i<n;i++) {
    scanf("%d %d",&qu[i],&qf[i]);
    //  printf("qu[%d] = %d qf[%d] = %d\n",i,qu[i],i,qf[i]);
  }
}

void N() {
  t = a[1];
  a[1] = a[2];
  a[2] = a[6];
  a[6] = a[5];
  a[5] = t;
}

void S() {
  t = a[1];
  a[1] = a[5];
  a[5] = a[6];
  a[6] = a[2];
  a[2] = t;
}

void E() {
  t = a[1];
  a[1] = a[4];
  a[4] = a[6];
  a[6] = a[3];
  a[3] = t;
}

void W() {
  t = a[1];
  a[1] = a[3];
  a[3] = a[6];
  a[6] = a[4];
  a[4] = t;
}

void UF() {

  if(qu[k] == a[1]) { // if qu == 1;
    // printf("qu == 1\n");
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[5]) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
  }  else if(qu[k] == a[2]) {  // if qu == 2;
    // printf("qu == 2\n");
    if(qf[k] == a[3])  strcpy( str, "NWS");
    else if(qf[k] == a[1] ) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
  } else if(qu[k] == a[3]){ // if qu == 3;
    //   printf("qu(%d) == %d\n",qu[k],a[3]);
    
    if(qf[k] == a[6])  strcpy( str, "NWS");
    else if(qf[k] == a[5])  strcpy(str ,"NEES");
    else if(qf[k] == a[1]) strcpy(str,"NES");
    W();
  } else if(qu[k] == a[4]) {
    if(qf[k] == a[1]) strcpy( str, "NWS");
    if(qf[k] == a[5])  strcpy(str ,"NEES");
    if(qf[k] == a[6]) strcpy(str,"NES");
    E();
  } else if(qu[k] == a[5]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[6])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    S();
  } else if(qu[k] == a[6]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[2])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
    N();
  }


}

void reset() {
  // printf("before reset str = '%s'\n",str);
  strcpy(str , "");
  for(i=1;i<=6;i++){
    //  printf("before reset a[%d] = %d\n",i,a[i]);
    a[i] = b[i];
    //     printf("a[%d] = %d\n",i,a[i]);
  }
  // printf("str = '%s'\n",str);
}


void output() {
  /*  printf("%d\n",a[1]); */

  printf("%d\n",a[3]);
}

void IF() {

  // scanf("%s",str);

  for(i=0;i<strlen(str);i++) {

    if(str[i] == 'N') N();
    else if(str[i] == 'S') S();
    else if(str[i] == 'W') W();
    else if(str[i] == 'E') E();
  }
}

int main() {

  k = 0;

  input();

  for(j=0;j<n;j++) {
    UF();
    
    IF();

    output();

    reset();
    k = k + 1;

  }

  //  strlen(?) ???????????????(??°)


  return 0;
}

Measured memory_bytes: 596
// C++ program to print words in a sentence 
#include <bits/stdc++.h> 
using namespace std; 
 
 
 
 
int main() 
{ 
    string s;
    cin>>s;
     
    int n; 
    cin>>n;
     
    while(n--){
         
        string q;
        cin>>q;
         
            if ("replace"==q){
            int a,b; cin>>a>>b;
            string z;
            cin>>z;
            for(int i=a; i<=b; i++){
                s[i]=z[i-a];
            }
            }
            else if("reverse"==q){
            int a,b;
            cin>>a>>b;
            while(a!=b){
                char temp = s[a];
                s[a] = s[b];
                s[b] = temp;
                if(b-a==1) break;
                a++;
                b--;
            }
            }
            else if( "print"==q){
            int a,b;
            cin>>a>>b;
            cout<<s.substr(a,b-a+1)<<endl;
            }
         
    }
     
     
     
    return 0; 
}


Measured memory_bytes: 3212
h_arr = []
w_arr = []
while true
  h, w = gets.split.map(&:to_i)
  break if h == 0 && w == 0
  h_arr.push(h)
  w_arr.push(w)
end
h_arr.zip(w_arr) do |h, w|
  h.times do
    w.times do
      print "#"
    end
    puts ""
  end
  puts ""
end



Measured memory_bytes: 8904
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int count[4][3][10] = {};
    int n, b, f, r, v;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        count[b-1][f-1][r-1] += v;
    }
    for (int j = 0; j < 4; j++){
        for (int k = 0; k < 3; k++){
            for (int l = 0; l < 10; l++){
                cout << " " << count[j][k][l];
            }
            cout << endl;
        }
        if (j != 3){
            cout << "####################" << endl;
        }
    }
}


Measured memory_bytes: 3080
n = int(input())
p = list(map(int, input().split()))
a = sorted([(p[i], i + 1) for i in range(n)])
count = 0
for i in a:
    if i[0] != i[1]:
        count += 1
if count <= 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   int n; cin>>n;
   vector<int> v(n),suf(n+1);
   rep(i,0,n)cin>>v[i];
   int ans=0;
   repd(i,n-1,0){
       suf[i]=(suf[i+1]+v[i])%mod;
   }
   rep(i,0,n){
            ans+=(v[i]*suf[i+1])%mod;
            ans%=mod;
   }
   cout<<ans<<"\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 6428
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define POS 1
#define INPOS -1
#define adj 100
#define rep(i, n) for(int i = 0 ; i < n ; i++)

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

struct State{
  int x, y;
  int turn;
  State(int xx, int yy, int t){
    x = xx, y = yy, turn = t;
  }
};

int field[200][200];
int t;
int sx, sy;

void bfs(){
  queue<State> que;
  que.push(State(sx, sy, t));
  while(!que.empty()){
    State tmp = que.front();
    que.pop();
    if(tmp.turn == 0) continue;
    rep(i, 6){
      int nx = tmp.x+dx[i], ny = tmp.y+dy[i];
      if(field[ny][nx] == POS) continue;
      if(field[ny][nx] != INPOS){
	field[ny][nx] = POS;
	que.push(State(nx, ny, tmp.turn-1));
      }
    }
  }
}
    
int main(){
  int n;
  int jx, jy;
  while(cin >> t >> n, t|n){
    memset(field, 0, sizeof(field));
    while(n--){
      cin >> jx >> jy;
      jx += adj, jy += adj;
      field[jy][jx] = INPOS;
    }
    cin >> sx >> sy;
    sx += adj, sy += adj;
    int ans = 0;
    field[sy][sx] = POS;
    bfs();
    rep(i, 200){
      rep(j, 200){
	if(field[i][j] == POS) ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1380
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;


int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}



int main()
{
	long long int m, d, cnt = 0;

	cin >> m >> d;

	for (int i = 22; i <= d; i++) {
		if (i % 10 >= 2) {
			if ((i / 10) * (i % 10) <= m)
				cnt++;
		}
	}
	
	cout << cnt << endl;
	

	return 0;

}

Measured memory_bytes: 256
from collections import deque

n = int(input())
queue = deque([1,2,3,4,5,6,7,8,9])

for _ in range(n):
  ans = queue.popleft()
  x = ans % 10
  if x != 0 :
    queue.append(ans * 10 + x - 1)
  queue.append(ans * 10 + x)
  if x != 9 :
    queue.append(ans * 10 + x + 1)
    
print(ans)

Measured memory_bytes: 18708
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,m;
  cin>>n>>m;
  priority_queue<int> q;
  rep(i,n){
    int a;
    cin>>a;
    q.push(a);
  }

  rep(i,m){
    int t=q.top(); q.pop();
    q.push(t/2);
  }

  int ans=0;
  rep(i,n){
    ans+=q.top(); q.pop();
  }
  cout<<ans<<endl;


}

Measured memory_bytes: 1400
A = [list(map(int, input().split(' '))) for  _ in range(3)]
N = int(input())
B = set([int(input()) for _ in range(N)])

X = []
X += [set(A[i]) for i in range(3)]
X += [set([A[j][i] for j in range(3)]) for i in range(3)]
X += [set([A[0][2], A[1][1], A[2][0]]), set([A[2][2], A[1][1], A[0][0]])]

for x in X:
  if x <= B:
    print('Yes')
    break
else:
  print('No')

Measured memory_bytes: 38256
import sys
import math
from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 

mx = int(math.pow(10, 5) + 1000)

def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]

n = load()
plist = prime_list(mx)
for i in range(len(plist)):
    if plist[i] >= n:
        print(plist[i])
        exit()

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

int main() {
  string s;
  cin >> s;
  int ans = 1000;
  for (int i = 0; i < s.length() - 2; i++) {
    string t = s.substr(i, 3);
    int x = stoi(t);
    ans = min(ans, abs(x - 753));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

string itos(const int i) {
    string s = to_string(i);
    return s;
}

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

    int count = 0;
    for (int i = 1; i <= n; i++) {
        string s = itos(i);
        if (s.length() % 2 == 1) {
            count++;
        } 
    }
    
    cout << count << endl;
    return 0;
}





Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll ans = 0;
	sort(a.rbegin(), a.rend());
	ans += a[0];
	int pos = 1;
	int cnt = 0;
	for (int i = 1; i < n - 1; i++) {
		ans += a[pos];
		cnt++;
		if (cnt == 2) {
			pos++;
			cnt = 0;
		}
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
bool compare(pair<ll,ll> p1,pair<ll,ll> p2){
return p1.se>p2.se;
}
void solve(){
  ll n,a;
  cin>>n;
  ll ans[n+1]={0};
  fr(i,0,n-1){
    cin>>a;
    ans[a]++;
  }
  fr(i,1,n+1) cout<<ans[i]<<endl;
}
int main()
{   fast;
    ll t=1;
    //cin>>t;
    fr(zz,1,t+1){
solve();
    }
}


Measured memory_bytes: 5180
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static void AssertEquals<T>(
				       T expected,
				       T actual,
				       [CallerLineNumber] int lno = 0
				       )
	where T : IComparable
    {
	if (expected.CompareTo(actual) != 0)
	{
	    WriteLine($"Assertion Error at line {lno}:");
	    WriteLine($"\texpected: {expected}");
	    WriteLine($"\t  actual: {actual}");
	    Environment.Exit(1);
	}
    }
    
    public static int Gcd(int a, int b)
    {
	if (a < b){ return Gcd(b, a); }
	while (b != 0)
	{
	    var r = a % b;
	    a = b;
	    b = r;
	}
	return a;
    }

    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static void WarshallFloyd(int[,] d, int v)
    {
	for (int k = 0; k < v; k++)
	    for (int i = 0; i < v; i++)
		for (int j = 0; j < v; j++)
		    d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
    }

    public static bool NextPermutation<T>(T[] a) where T : IComparable
    {
	if (a.Length <= 1) return false;

	for (int i = a.Length - 1; i > 0; i--)
	{
	    int k = i - 1;
	    if (a[k].CompareTo(a[i]) < 0)
	    {
		int j = a.Length - 1;
		while (a[k].CompareTo(a[j]) >= 0){ j--; }
		Swap(ref a[k], ref a[j]);
		Array.Reverse(a, i, a.Length - i);
		return true;
	    }
	}
	Array.Reverse(a);
	return false;
    }
    
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int inf = (1 << 29);
	
	var tmp = ReadIntArray();
	int n = tmp[0], m = tmp[1], r = tmp[2];

	int[] rs = ReadIntArray();
	for (int i = 0; i < r; i++) rs[i]--;
	Array.Sort(rs);

	int[,] d = new int[n, n];
	for (int i = 0; i < n; i++)
	{
	    for (int j = 0; j < n; j++)
	    {
		if (i != j) d[i, j] = inf;
	    }
	}

	for (int i = 0; i < m; i++)
	{
	    tmp = ReadIntArray();
	    int a = tmp[0], b = tmp[1], c = tmp[2];
	    a--; b--;
	    d[a, b] = c;
	    d[b, a] = c;
	}

	WarshallFloyd(d, n);

	int ans = inf;
	do
	{
	    int dist = 0;
	    for (int i = 0; i < r - 1; i++)
	    {
		dist += d[rs[i], rs[i+1]];
	    }
	    ans = Math.Min(ans, dist);
	} while (NextPermutation(rs));

	WriteLine(ans);
    }
}


Measured memory_bytes: 15416
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let _ = line.trim().parse::<usize>().unwrap();
    let line = gets();
    let mut v: Vec<i128> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i128>().unwrap())
        .collect();
    v.sort();
    let mut ans = 1;
    for x in v {
        if x == 0 {
            println!("0");
            return;
        }
        ans *= x;
        if ans > 1000000000000000000 {
            println!("-1");
            return;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6032
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int  main() {
	
	int n;
	vector<ll>a, b, c;
	ll ans = 0;

	cin >> n;
	rep(i, n) {
		int z;
		cin >> z;
		a.push_back(z);
	}
	rep(i, n) {
		int z;
		cin >> z;
		b.push_back(z);
	}
	rep(i, n) {
		int z;
		cin >> z;
		c.push_back(z);
	}

	sort(all(a));
	sort(all(b));
	sort(all(c));

	for (int i = 0; i < n; i++) {
		decltype(a)::iterator ai = lower_bound(a.begin(), a.end(), b[i]);
		decltype(c)::iterator ci = upper_bound(c.begin(), c.end(), b[i]);
		ans += (ai - a.begin()) *( c.end() - ci);
	}
	pr(ans);

	return 0;

}

Measured memory_bytes: 3316
n=int(input())

l=list(map(int,input().split()))

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm1[0])
else:
    if km1[0]-km2[0]>=gm1[0]-gm2[0]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])


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

int main() {
	int a[4];


	cin >> a[0];
	cin >> a[1];
	cin >> a[2];

	for (int i = 0; i < 3; i++)
	{
		if (a[i] > a[2])
		{
			a[4] = a[2];
			a[2] = a[i];
			a[i] = a[4];
		}
		if (a[i] < a[0])
		{
			a[4] = a[0];
			a[0] = a[i];
			a[i] = a[4];
		}
	}


	for (int i = 0; i < 3; i++)
	{
		cout << a[i];
		if (i != 2)
			cout << " ";
		else
			cout << endl;
	}
	

	return 0;
}

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

int bubbleSort(int A[], int N) {
    int swapCount = 0;
    bool sorted = false;
    while(!sorted){
        sorted = true;
        for ( int i = 0; i < N-1; i++ ) {
            if ( A[i] > A[i+1] ) {
                swap(A[i], A[i+1]);
                sorted = false;
                swapCount++;
            }
        }
        N--;
    }
    return swapCount;
}

int main() {
    int A[100], N, sw;
    cin >> N;
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    
    sw = bubbleSort(A, N);
    
    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3108
uses math;
var
  i,j,k,n,m:longint;
  s1,s2,s3:string;
begin
  readln(s1);
  readln(s2);
  i:=length(s1);
  j:=length(s2);
  n:=min(i,j);
  m:=max(i,j);
  for k:=1 to n do write(s1[k],s2[k]);
  if i>j then
    for k:=n+1 to m do
      write(s1[k])
    else
    for k:=n+1 to m do
      write(s2[k]);
  writeln; 
end.



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

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

	double sum_pro = 0;
	for(int i = 1; i <= n; i++){
		int now = i;
		double pro = 1;
		while(now < k){
			pro *= 0.5;
			now *= 2;
		}
		sum_pro += pro/n;
	}

	cout << fixed << setprecision(10) << sum_pro << endl;

	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> field(h, vector<int>(w, 0));
	vector<vector<int>> id(h, vector<int>(w, -1));
	for (int y = 0; y < h; ++y) {
		string s;
		cin >> s;
		for (int x = 0; x < w; ++x) {
			if (s[x] == '#') {
				field[y][x] = 1;
			}
			else {
				field[y][x] = 0;
			}
		}
	}

	int maxid = 0;
	vector<pair<int64_t, int64_t>> res;
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			if (id[y][x] == -1) {
				queue<pair<int, int>> q;
				q.push(make_pair(x, y));
				id[y][x] = maxid;
				int64_t white, black;
				white = black = 0;
				if (field[y][x] == 1) black++;
				else white++;

				while (!q.empty()) {
					auto p = q.front();
					int cx = p.first;
					int cy = p.second;
					q.pop();
					int dx[] = { 1,0,-1,0 };
					int dy[] = { 0,1,0,-1 };
					for (int d = 0; d < 4; ++d) {
						int nx = cx + dx[d];
						int ny = cy + dy[d];
						if (0 <= nx && nx < w) {
							if (0 <= ny && ny < h) {
								if (id[ny][nx] == -1) {
									if (field[cy][cx] != field[ny][nx]) {
										id[ny][nx] = maxid;
										if (field[ny][nx] == 1) black++;
										else white++;
										q.push(make_pair(nx, ny));
									}
								}
							}
						}
					}
				}
				res.push_back(make_pair(white, black));
				maxid++;
			}
		}
	}
	int64_t sum = 0;
	for (auto item : res) {
		sum += item.first * item.second;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 6644
def inpl():
    return list(map(int, input().split()))


def count(i):
    cost, k = 0, 1
    h = A[0]
    for j in range(1, N):
        if A[j] > h:
            k += 1
            h = A[j]
        elif (i >> j) & 1:
            k += 1
            cost += max(h - A[j] + 1, 0)
            h += 1
    return cost, k


N, K = inpl()
A = inpl()

ans = float('inf')
for i in range(1 << N):
    cost, k = count(i)
    if k >= K:
        ans = min(ans, cost)

print(ans)


Measured memory_bytes: 44636