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

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int[] test = new int[N];
		for (int i = 0; i < N; i++) {
			test[i] = input.nextInt();
		}
		System.out.println(JUMP(test));
	}
	public static int JUMP(int[] test) {
		if (test.length==2) return Math.abs(test[1]-test[0]);
		int[] dp = new int[test.length];
		dp[0]=0;
		dp[1]=Math.abs(test[1]-test[0]);
		for (int i = 2; i < test.length; i++) {
			dp[i]=Math.min(dp[i-1]+Math.abs(test[i]-test[i-1]), dp[i-2]+Math.abs(test[i]-test[i-2]));
		}
		return dp[test.length-1];
	}
}

Measured memory_bytes: 51380
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 5;
int a[N];

int main()
{
	int n;
	while(~scanf("%d",&n)){
		for(int i = 0; i < n; i++)
			scanf("%d",&a[i]);
		sort(a,a+n);
		int sum = 0;
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				for(int k = n - 1; k >= j + 1; k--){
					if(a[i] + a[j] <= a[k])
						sum++;
					else
						break;		
				}
			}
		}
		int ans = 0;
		for(int i = 1; i <= (n - 2)/2; i++)
			ans += (i * (n-1-i))*2;	
		if(n % 2 == 1)
			ans += ((n-2)/2+1) * ((n-2)/2+1);
		printf("%d\n",ans - sum);
	}
	return 0;
} 

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> wyst(100001, 0);
    ll s = 0;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        ++wyst[x];
        s += x;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i)
    {
        ll a, b;
        cin >> a >> b;
        s -= wyst[a] * a;
        s += wyst[a] * b;
        wyst[b] += wyst[a];
        wyst[a] = 0;
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
int k[300005];
int main() {
	int n;
	string s;
	cin >> n >> s;
	for (int i = 1; i < n; i++){
		if (s[i] == 'E') {
			k[0]++;
		}

	}
	
	for (int t = 1; t<n; t++) {
		if (s[t - 1] == 'W' && s[t] == 'W') {
			k[t] = k[t - 1] + 1;
		}
		else if (s[t - 1] == 'E'&& s[t] == 'E') {
			k[t] = k[t - 1] - 1;
		}
		else {
			k[t] = k[t - 1];
		}
	}
	int mon = 1000000;
	for (int t = 0; t<n; t++) {
      mon=min(k[t],mon);
	}

	cout << mon << endl;
}


Measured memory_bytes: 1796
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)

	const max = 1000
	mpp := make(map[int]int)
	mpn := make(map[int]int)
	for i := 0; i <= max; i++ {
		k := i * i * i * i * i
		mpp[k] = i
		if v, ok := mpp[x+k]; ok {
			fmt.Println(i, v)
			return
		}
	}
	for i := 1; i >= -1*max; i-- {
		k := i * i * i * i * i
		mpn[k] = i
		if v, ok := mpp[x+k]; ok {
			fmt.Println(v, i)
			return
		}
		if v, ok := mpn[x+k]; ok {
			fmt.Println(v, i)
			return
		}
	}
}


Measured memory_bytes: 1936
import sys
import collections
import copy
import math
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
N,K,Q =map(int,input().split())
A=[0]* N
for i in range(Q):
    A[int(input())-1] +=1
S = sum(A)
for i in range(N):
    if K-Q+A[i] > 0:
        print("Yes")
    else:
        print("No")


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

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

  int a[100][100] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int b[100] = {};
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  int c[100] = {};
  for(int i = 0; i < n; i++){
    for (int j = 0; j < m; j++) {
      c[i] += a[i][j]*b[j];
    }
  }

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



Measured memory_bytes: 3132
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main (final String[] args) {
        final Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = str.length();
        char last = str.charAt(n-1);
        
        if (last == '3') System.out.println("bon");
        else if (last == '0' || last == '1' || last == '6' || last == '8') System.out.println("pon");
        else System.out.println("hon");
        
    }
}

Measured memory_bytes: 35500
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k)
        cout<<k<<endl;
    else if(k<=a+b)
        cout<<a<<endl;
    else
    {
        int ans=0;
    int a1=a*1;
    int b1=b*0;
    ans=k-(a+b);
    int c1=ans*(-1);
    cout<<a1+b1+c1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric> // 最大公約数が使える
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9

int main(){
    string S;
    cin >> S;
    if(S=="ABC"){
        cout << "ARC" << endl;
    }   else
    {
        cout << "ABC" << endl;
    }
    
}

Measured memory_bytes: 3620
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;

procedure main is
   S: String(1..3);
begin
   S := get_line;
   if (S(2) = 'B') then S(2) := 'R';
   else S(2) := 'B';
   end if;
   put_line(S);
end main;

Measured memory_bytes: 3552
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        String s=sc.next();
        
        if(s.equals("SUN")){
            System.out.println('7');
        }
        if(s.equals("MON")){
            System.out.println('6');
        }
        if(s.equals("TUE")){
            System.out.println('5');
        }
        if(s.equals("WED")){
            System.out.println('4');
        }
        if(s.equals("THU")){
            System.out.println('3');
        }
        if(s.equals("FRI")){
            System.out.println('2');
        }
        if(s.equals("SAT")){
            System.out.println('1');
        }
    }
}

Measured memory_bytes: 21844
N = int(input())
A = [int(input()) for _ in range(N)]

left = [0]
l = 1
for i in A:
    l = max(l,i)
    left.append(l)
right = [0]
r = 1
for i in A[::-1]:
    r = max(r,i)
    right.append(r)
    
for i in range(N):
    print(max(left[i],right[-i-2]))

Measured memory_bytes: 77396
#include<bits/stdc++.h>
using namespace std;
long long ceil(long long a,long long b){if(a%b==0)return a/b;else return (a/b+1);}
long long max(long long a,int long long b){if(a>b)return a;else return b;}
vector<int>w;
vector<int>val;
int n,W;
long long dp[105][100005];
long long knapsack(int i,int we)
{
if(i>=n)
return 0;
if(dp[i][we]!=-1)
return dp[i][we];
if(w[i]<=we){
long long right=knapsack(i+1,we);
long long left=knapsack(i+1,we-w[i])+val[i];
return dp[i][we]=max(left,right);
}
else
return dp[i][we]=knapsack(i+1,we);
}

int main()
{
	memset(dp,-1,sizeof(dp));
	
	cin>>n>>W;
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		w.push_back(x);
		val.push_back(y);
	}
	
	cout<<knapsack(0,W)<<endl;  	
        
}

Measured memory_bytes: 85504
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        long a = vals[0];
        long b = vals[1];
        long c = vals[2];
        long k = vals[3];

        var diff = (k % 2 == 0) ? a - b : -a + b;

        if (Math.Abs(diff) > 1000000000000000000)
        {
            Console.WriteLine("Unfair");
        }
        else
        {
            Console.WriteLine(diff);
        }
    }
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    string S; cin >> S;

    string tmp1, tmp2;
    ll siz = S.size();
    for(int i = 0; i < siz; ++i) {
        S.pop_back();
        if(S.size() % 2 == 0) {
            tmp1 = S.substr(0, S.size() / 2);
            tmp2 = S.substr(S.size() / 2);
            if(tmp1 == tmp2) break;
        } else {
            continue;
        }
    }
    cout << tmp1.size() + tmp2.size() << endl;
}


Measured memory_bytes: 256
// at_abc143d.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int sticks;cin >> sticks;
    vector<int>v(sticks, 0);
    for (int i = 0;i < sticks;i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    long long ans = 0;
    for (int i = 0;i < sticks;i++) {
        for (int a = i + 1; a < sticks;a++) {
            for (int j = a + 1; j < sticks;j++) {
                if (v[i] + v[a] > v[j]) {
                    ans++;
                }
                else {
                    break;
                }
            }
        }
    }
    cout << ans << "\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


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

int n, a, cnt[100010], sol = 0;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a > 0) cnt[a - 1]++;
		cnt[a]++;
		cnt[a + 1]++;
	}
	for (int i = 0; i < 100010; i++) sol = max(sol, cnt[i]);
	cout << sol;
}

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

using ll = long long;
constexpr ll M = 1e9 + 7;

// 0-indexed
template <typename T>
class fenwick_tree {
public:
    fenwick_tree(int n) : n(n), dat(n, 0) {}

    void add(int i, T value) {
        for(; i<n; i |= i + 1) {
            dat[i] += value;
        }
    }

    // [0, i)
    T sum(int i) const {
        T res = 0;
        for(; i>=0; i = (i & (i+1)) - 1) {
            res += dat[i];
        }
        return res;
    }
    // [l, r)
    T sum(int l, int r) const {
        return sum(r-1) - sum(l-1);
    }

    T get(int i) const {
        return sum(i) - sum(i - 1);
    }

private:
    const int n;
    std::vector<T> dat;
};


int main() {
    ll N, Q, S, T;
    cin >> N >> Q >> S >> T;
    vector<ll> A(N + 1);
    for(int i = 0; i <= N; ++i) {
        cin >> A[i];
    }

    fenwick_tree<ll> bit(N);
    for(int i = 0; i < N; ++i) {
        if(A[i] < A[i + 1]) {
            bit.add(i, (A[i] - A[i + 1]) * S);
        } else {
            bit.add(i, (A[i] - A[i + 1]) * T);
        }
    }

    while(Q--) {
        int l, r, x;
        cin >> l >> r >> x;
        ll L = bit.get(l - 1), R = bit.get(r);
        ll new_L = L / (L < 0 ? S : T) - x;
        ll new_R = R / (R < 0 ? S : T) + x;
        bit.add(l - 1, -L + new_L * (new_L < 0 ? S : T));
        bit.add(r, -R + new_R * (new_R < 0 ? S : T));
        cout << bit.sum(0, N) << endl;
    }
}


Measured memory_bytes: 5988
#include<stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,a[N][N],color[N],d[N],f[N],time;
void dfs(void);
void visit(int);

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      a[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u][v]=1;
    }
  }

  dfs();
  return 0;
}


void dfs(void){
  int u;
  
  for(u=1;u<=n;u++){
    color[u]=WHITE;
  }
  time=0;
  for(u=1;u<=n;u++){
    if(color[u]==WHITE)
      visit(u);
  }
  for(u=1;u<=n;u++){
    printf("%d %d %d\n",u,d[u],f[u]);
  }
}


void visit(int u){
  int v;

  color[u]=GRAY;
  d[u]=++time;
  for(v=1;v<=n;v++){
    if(a[u][v]==0)
      continue;
    if(color[v]==WHITE)
      visit(v);
  }
  color[u]=BLACK;
  f[u]=++time;
}

Measured memory_bytes: 636
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        l: f64
    }
    let r = l / 3.0;
    println!("{}", r*r*r);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
n = input()
 
M = [[float("inf") for j in xrange(n)] for i in xrange(n)]
color = ['WHITE' for i in xrange(n)]
d = [float("inf") for i in xrange(n)]
p = [-1 for i in xrange(n)]
 
for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(n):
        if tmp[j] != -1:
            M[i][j] = tmp[j]
 
d[0] = 0
p[0] = -1
 
while 1:
    mincost = float("inf")
    for i in xrange(n):
        if color[i] != "BLACK" and d[i] < mincost:
            mincost = d[i]
            u = i
 
    if mincost == float("inf"):
        break
 
    color[u] = "BLACK"
 
    for v in xrange(n):
        if color[v] != "BLACK" and M[u][v] != -1 and M[u][v] < d[v]:
            d[v] = M[u][v]
            p[v] = u
            color[v] = "GRAY"
 
 
sum = 0
 
for i in xrange(n):
    sum += d[i]
 
print sum

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

int main(){
    int a, b; cin >> a >> b;
    string c = "", d = "", e, f;
    e = to_string(a);
    f = to_string(b);
    for(int i = 0; i < b; i++){
        c = c + e;
    }
    for(int i = 0; i < a; i++){
        d = d + f;
    }
    if(c > d){
        cout << d << endl;
    }else{
        cout << c << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;
 
int main() {
  ll N;
  ll cnt = 0;
  ll max = 0;
  string S;
  cin >> N >> S;
  vector<bool> letterL(26);
  vector<bool> letterR(26);
  for(ll i = 0; i < N; i++) {
    for(ll j = 0; j < i + 1; j++) letterL.at(int(S.at(j)) - 97) = 1;
    for(ll j = i + 1; j < N; j++) letterR.at(int(S.at(j)) - 97) = 1;
    for(ll j = 0; j < 26; j++) {
      if((letterL.at(j) == 1) && (letterR.at(j) == 1)) cnt++;
    }
    if(cnt >= max) max = cnt;
    cnt = 0;
    for(ll j = 0; j < 26; j++) letterL.at(j) = 0;
    for(ll j = 0; j < 26; j++) letterR.at(j) = 0;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))

ans = 0
height = h[0]
count = 0
i = 1
while i < n:
	if h[i] <= height:
		count += 1
		height = h[i]
		i += 1
	else:
		ans = max(ans,count)
		count = 0
		height = h[i]
		i += 1
print(max(ans,count))


Measured memory_bytes: 63984
S = str(input()) + 'X'
l = len(S)
x = 0
list = []
for i in range(l):
	if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C' :
		x = x + 1
	else:
		list.append(x)
		x = 0
print(max(list))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
struct data{
	int y,nxt;
}e[1000010];
int a[10010],n;
int head[10010],cnt;
void add(int x,int y){
	cnt++;
	e[cnt].y=y;
	e[cnt].nxt=head[x];
	head[x]=cnt;
}
bool dfs(int x,int fa,int s){
	bool can=0,ans=1,fg=0;
	for(int i=head[x];i;i=e[i].nxt){
		int y=e[i].y;
		if(fa==y||a[y]>=a[x]) continue;
		bool u=dfs(y,x,s+1);
		if(s%2==0) ans&=u;
		can=true,fg|=u;
	}
	//cout<<x<<" "<<s<<" "<<ans<<" "<<fg<<" "<<can<<endl;
	return (ans&fg)|((!can)&(s%2==0));
}
bool flag;
int main(){
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i=1;i<=n;i++){
		flag=dfs(i,-1,1);
		if(flag) printf("%d\n",i);
	}
} 

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

double pw;
vector<double> vw, pf, vf, th;
double calc(double W) {
    int N = vw.size();
    double res = W * pw;

    REP(i, N) {
        double F = (th[i] - vw[i] * W) / vf[i];
        if(F > 0) {
            res += pf[i] * F;
        }
    }

    return res;
}

double find_min(double a, double b, double f(double)) {
    REP(_, 86) {
        double c = (a * 2 + b) / 3;
        double d = (a + b * 2) / 3;
        if(f(c) < f(d)) {
            b = d;
        } else {
            a = c;
        }
    }
    return (a + b) / 2;
}
static const double RATIO = (1 + sqrt(5.0)) * 0.5;
double find_min_fast(double left, double right, double f(double)){
	double leftValue = f((left * RATIO + right) / (1 + RATIO));
	double rightValue = f((left + right * RATIO) / (1 + RATIO));
	for (int loop = 0; loop < 72; ++loop){
		if (leftValue < rightValue){
			right = (left + right * RATIO) / (1 + RATIO);
			rightValue = leftValue;
			leftValue = f((left * RATIO + right) / (1 + RATIO));
		} else {
			left = (left * RATIO + right) / (1 + RATIO);
			leftValue = rightValue;
			rightValue = f((left + right * RATIO) / (1 + RATIO));
		}
	}
	if (leftValue < rightValue){
		right = (left + right * RATIO) / (1 + RATIO);
	} else {
		left = (left * RATIO + right) / (1 + RATIO);
	}
	return (right + left) * 0.5;
}

int main(){
    int N;
    while(cin >> N && N > 0) {
        cin >> pw;
        vw.resize(N);
        pf.resize(N);
        vf.resize(N);
        th.resize(N);
        REP(i, N) {
            cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
        }

        /*
        double lb = 0, ub = 1000;
        REP(_, 100) {
            double left = (lb * 2 + ub) / 3;
            double right = (lb + ub * 2) / 3;
            if(calc(left) < calc(right)) {
                ub = right;
            } else {
                lb = left;
            }
        }
        */

        double x = find_min_fast(0, 1000, calc);

        printf("%.12lf\n", calc(x));
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

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

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

bool era[252525];

int main(){
  int a,b,n;
  while(~scanf("%d%d%d",&a,&b,&n)){
    a %= b;
    int sum = 0;
    REP(i,n){
      a *= 10;
      sum += a/b;
      a %= b;
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
N,M = map(int,input().split())

AC=[0]*N
WA=[0]*N
WAtimes=0
ACtimes=0

for i in range(M):
  p,S=map(str,input().split())
  p=int(p)-1
  if 'AC'==S:
    if 0==AC[p]:
      ACtimes+=1
      WAtimes+=WA[p]
    AC[p]+=1
  if 'WA'==S:
    WA[p]+=1

print(ACtimes,WAtimes)

Measured memory_bytes: 4596
#include<iostream>
using namespace std;
int dp[1401][1401]={},m,h,w,f;
#define r(i,n) for(int i=0;i<n;i++)
main(){
cin>>h>>w;m=0;
r(i,h)r(j,w){cin>>f;if(!f)dp[i+1][j+1]=min(dp[i][j],min(dp[i+1][j],dp[i][j+1]))+1,m=max(m,dp[i+1][j+1]);}
cout<<m*m<<endl;
}


Measured memory_bytes: 9664
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = stdIn.nextInt();
      if (( a < b ) && ( b < c )) {
         System.out.println( "Yes" );
      } else {
         System.out.println( "No" );
      }
   }
}

Measured memory_bytes: 26116
io = STDIN
n,a,b=io.gets.chomp.split.map(&:to_i)
x=io.gets.chomp.split.map(&:to_i)

ar = x.each_cons(2).map do |i,j|
  dist = j-i
  [dist*a,b].min
end
p ar.inject(:+)

Measured memory_bytes: 12932
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n ,k;
    cin >> n >> k;
    ll a[n+1];
    for(ll i =1 ; i <= n ;  i++)
    cin >> a[i];


    ll dp[n+1];
    for(ll i = 0 ; i <=n ; i++)
    {
        dp[i] = 1e18;
    }
    dp[1] = 0;
    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = i-1 ; j >= max((ll)(1) , (i-k)) ; j--)
        {
            dp[i] = min(dp[j]+abs(a[i]-a[j]) , dp[i]);
        }
    }

    cout << dp[n];
    


    



}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

  int d = a[0] + (k - a[n - 1]);
  for (int i = 1; i < n; i ++) {
    d = max(d, a[i] - a[i - 1]);
  }

  cout << k - d << endl;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9+7

n = int(input())
l = len(input().rstrip())
dp = [[0]*(i+1) for i in range(n+1)]
for i in range(n+1):
  for j in range(i+1):
    if i == 0:
      dp[0][0] = 1
    else:
      dp[i][j] = dp[i-1][max(j-1, 0)]
      if i-1 >= j+1:
        dp[i][j] += 2*dp[i-1][j+1]
      dp[i][j] %= MOD
ans = dp[n][l]
print(ans)

Measured memory_bytes: 138460
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		sc.close();
		int[][][][] dp = new int[101][4][4][4];
		dp[0][3][3][3] = 1;
		int Mod = 1000_000_007;

		//文字列の文字数
		for (int len = 0; len < n; len++)
		{
			//最後から1文字目の文字
			for (int c1 = 0; c1 < 4; c1++)
			{
				//最後から2文字目の文字
				for (int c2 = 0; c2 < 4; c2++)
				{
					//最後から3文字目の文字
					for (int c3 = 0; c3 < 4; c3++)
					{
						//条件に当てはまるものがない場合はcontinue;
						if (dp[len][c1][c2][c3] == 0) continue;

						//新しく追加する文字
						for (int a = 0; a < 4; a++)
						{
							//ダメな5つの条件をカットする
							if (a == 2 && c1 == 1 && c2 == 0) continue;
							if (a == 2 && c1 == 0 && c2 == 1) continue;
							if (a == 1 && c1 == 2 && c2 == 0) continue;
							if (a == 2 && c1 == 1 && c3 == 0) continue;
							if (a == 2 && c2 == 1 && c3 == 0) continue;

							//ダメな条件を抜けたら、aを足した文字列が作れる

							// S = ...... c3 c2 c1
							// nextS = ...... c2 c1 a

							dp[len + 1][a][c1][c2] += dp[len][c1][c2][c3];
							if(dp[len + 1][a][c1][c2]>Mod)dp[len + 1][a][c1][c2] -= Mod;
						}
					}
				}
			}
		}

		int res = 0;

		//長さNの全部の答えを纏める
		//最後から1文字目の文字
		for (int c1 = 0; c1 < 4; c1++)
		{
			//最後から2文字目の文字
			for (int c2 = 0; c2 < 4; c2++)
			{
				//最後から3文字目の文字
				for (int c3 = 0; c3 < 4; c3++)
				{
					res += dp[n][c1][c2][c3];
					if(res > Mod)res-=Mod;
				}
			}
		}
		System.out.println(res);
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}

const int INF = 1 << 20;
const int MOD = 1e9 + 7;

int main() {
   int x;
   cin >> x;
   if (x == 3 || x == 5 || x == 7)
      cout << "YES" << endl;
   else
      cout << "NO" << endl;
   return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [ord(a) - 97 for a in input()]
NN = 19
BIT=[[0]*(2**NN+1) for _ in range(26)]
 
def addbit(t, i, x):
    while i <= 2**NN:
        BIT[t][i] += x
        i += i & (-i)

def getsum(t, i):
    ret = 0
    while i != 0:
        ret += BIT[t][i]
        i -= i&(-i)
    return ret

for i, a in enumerate(A):
    addbit(a, i+2, 1)

Q = int(input())
for _ in range(Q):
    a, b, c = input().rstrip().split()
    if a == "1":
        b = int(b)
        c = ord(c) - 97
        t = A[b-1]
        addbit(t, b+1, -1)
        addbit(c, b+1, 1)
        A[b-1] = c
    else:
        b, c = int(b), int(c)
        s = 0
        for t in range(26):
            s += 1 if getsum(t, c+1) - getsum(t, b) else 0
        print(s)


Measured memory_bytes: 152224
w,h,x,y = map(int,input().split())
if x==0 or y==0:
    print("{:.9f}".format(w*h/2),0)
    exit()
if w/x==2.0 and h/y==2.0:
    print(w*h/2,1)
else:
    print(w*h/2,0)

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

#define ll long long
#define forr(i,n) for(ll i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

ll power(ll a,ll b){ll r=1;while(b--)r*=a;return r;}
int solve(vector<vector<int>> v,int n,vector<vector<int>> dp){
    for(int i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][1]+v[i-1][0],dp[i-1][2]+v[i-1][0]);
        dp[i][1]=max(dp[i-1][0]+v[i-1][1],dp[i-1][2]+v[i-1][1]);
        dp[i][2]=max(dp[i-1][1]+v[i-1][2],dp[i-1][0]+v[i-1][2]);
    }
    return max(dp[n][0],max(dp[n][1],dp[n][2]));
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int n;cin>>n;
    vector<vector<int>> v(n,vector<int>(3,0)),dp(n+3,vector<int>(3,0));
    f(i,0,n)cin>>v[i][0]>>v[i][1]>>v[i][2];
    cout<<solve(v,n,dp);
  
    
    

  }


Measured memory_bytes: 25016
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;
struct POINT{
    double x,y;
};

void koch(int n,POINT a,POINT b){
    if(n==0)return;
    POINT s,t,u;
    double th=(M_PI/180.0)*60.0;
    
    s.x=(2.0*a.x+1.0*b.x)/3.0;
    s.y=(2.0*a.y+1.0*b.y)/3.0;
    t.x=(2.0*b.x+1.0*a.x)/3.0;
    t.y=(2.0*b.y+1.0*a.y)/3.0;
    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}

int main(void){
    POINT a,b;
    int n;
    scanf("%d",&n);
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
    
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    
    return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> hi(N);
    REP(i, N)
    cin >> hi.at(i);
    REP(j, N)
    {
        if (j == 0)
        {
            hi.at(j)--;
            continue;
        }
        if (hi.at(j) < hi.at(j - 1))
        {
            cout << "No" << endl;
            return 0;
        }
        else if (hi.at(j) > hi.at(j - 1))
        {
            hi.at(j)--;
        }
        else
        {
            continue;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1152
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    for (i in 1..3500){
        for (j in 1..3500){
            val I = i.toLong()
            val J = j.toLong()
            val p : Long = I*J*n
            val q : Long = 4*I*J-I*n-J*n
            if (q > 0 && p % q == 0.toLong()){
                println(I.toString() + " " + J.toString() + " " + (p/q).toString())
                return
            }
        }
    }
}

Measured memory_bytes: 31668
n = gets.chomp.to_i
inputs = []
ans = Array.new(n, 0)
n.times do |i|
    sp = gets.chomp.split(" ")
    sp << i
    sp[1] = sp[1].to_i
    inputs << sp
end
inputs.sort!{|a, b| a[1] <=> b[1]}.reverse!
i = 0
arr = inputs.sort_by{|v| [v[0], i+=1]}
arr.each do |_, _, res|
    puts res+1
end

Measured memory_bytes: 1788
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<double> v(n);
    rep(i, n){
        cin >> v[i];
    }
    SORT(v);

    double ans = v[0];
    rep(i, n){
        ans = (ans + v[i]) / 2.0;
    }

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

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 28;
const double EPS = 1E-10;

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

bool xy[600][600];
bool yz[600][600];
bool xz[600][600];

int main(){
	int n, h;
	string s;
	int a, b;
	while(cin >> n >> h && (n || h)){
		memset(xy, false, sizeof(xy));
		memset(yz, false, sizeof(yz));
		memset(xz, false, sizeof(xz));
		int res = n * n * n;
		rep(i, h){
			cin >> s >> a >> b;
			a--, b--;
			if(s == "xy"){
				if(xy[a][b]) continue;
				xy[a][b] = true;
				rep(i,n){
					if(!xz[a][i] && !yz[b][i]) res--;
				}
			}else if(s == "yz"){
				if(yz[a][b]) continue;
				yz[a][b] = true;
				rep(i, n){
					if(!xy[i][a] && !xz[i][b]) res--;
				}
			}else{
				if(xz[a][b]) continue;
				xz[a][b] = true;
				rep(i, n){
					if(!xy[a][i] && !yz[i][b]) res--;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int n, a, b, ans = 0;
  long long x;
  string s;
  cin >> n;
  for(int i = 0; i < 10; i++) {
  }
  a = n / 100;
  b = n % 100;
  if(a <= 12 && a && b <= 12 && b) cout << "AMBIGUOUS" << endl;
  else if (a <= 12 && a) cout << "MMYY" << endl;
  else if (b <= 12 && b) cout << "YYMM" << endl;
  else cout << "NA" << endl;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]

for i in range(m):
    A[i][2] = -A[i][2]

P = [float("inf")] * (n+1)
P[1] = 0
F = [[0] * 2 for i in range(n+1)]
F[1][0] = 1
F[n][1] = 1

for i in range(n):
    for j in range(m):
        if F[A[j][0]][0] == 1 :
            F[A[j][1]][0] = 1
        if F[A[j][1]][1] == 1 :
            F[A[j][0]][1] = 1
        P[A[j][1]] = min(P[A[j][1]], P[A[j][0]] + A[j][2])

ans0 = P[:]

for i in range(1):
    for j in range(m):
        if F[A[j][0]][0] == 1 :
            F[A[j][1]][0] = 1
        if F[A[j][1]][1] == 1 :
            F[A[j][0]][1] = 1
        P[A[j][1]] = min(P[A[j][1]], P[A[j][0]] + A[j][2])

ans1 = P[:]

#print(F)

def d():
    for i in range(n+1):
        if F[i] == [1, 1] and ans1[i] < ans0[i]:
            return "inf"
    return -ans0[n]

print(d())

Measured memory_bytes: 49368
import java.io.*;
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int W = in.nextInt();

    int w[] = new int[n];
    long v[] = new long[n];

    for(int i=0;i<n;i++){
      w[i] = in.nextInt();
      v[i] = in.nextLong();
    }

    long dp[][] = new long[n+1][W+1];

    for(int i=1;i<=n;i++){
      for(int j=1;j<=W;j++){
        dp[i][j] = Math.max(dp[i-1][j], (j-w[i-1] >= 0 ) ? dp[i-1][j-w[i-1]] + v[i-1] : 0);
      }
    }
    System.out.println(dp[n][W]);
  }
}

Measured memory_bytes: 125524
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;

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

    int min = k - n+1;
    int max = k + n-1;

    for( int i = min;i<=max;i++){
        cout << i << " " ;
    }
    cout << endl;
}






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




int main(){
    ll N;
    cin >> N;
    vector<double> kati(N,0);
    for(int i=0;i<N;i++){
        cin>>kati[i]
    ;}
    sort(kati.begin(), kati.end());
    double ans=kati[0];
    for(int i=1;i<N;i++){
        ans=(ans+kati[i])/2
    ;}
    cout<<ans<<endl;
return 0;


}  



Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;
use std::collections::VecDeque;
use std::cmp::max;

struct Node {
    edge: Vec<(usize, usize)>,
}

struct Tree {
    nodes: Vec<Node>,
}

impl Node {
    fn new() -> Self {
        Node {
            edge: Vec::new(),
        }
    }
}

impl Tree {
    fn new(n: usize) -> Self {
        Tree {
            nodes: (0..n).map(|_| Node::new()).collect(),
        }
    }

    fn add_edge(&mut self, a: usize, b: usize, i: usize) {
        self.nodes[a].edge.push((b, i));
        self.nodes[b].edge.push((a, i));
    }
}

fn main()
{
    input! {
    n:usize,
    e:[(Usize1,Usize1);n-1],
    }

    let mut tree = Tree::new(n);
    for (i, &(a, b)) in e.iter().enumerate() {
        tree.add_edge(a, b, i);
    }

    let mut ans = vec![0; n - 1];
    let mut mx = 0;
    let mut q = VecDeque::new();
    q.push_back((0, 0));
    while let Some((t, col)) = q.pop_back() {
        let mut m = 0;
        for &(node, edge) in tree.nodes[t].edge.iter() {
            if ans[edge] > 0 {
                continue;
            }
            m += 1;
            if m == col {
                m += 1;
            }
            ans[edge] = m;
            q.push_back((node, m));
        }
        mx = max(mx, m );
    }

    println!("{}", mx);
    for &i in ans.iter() {
        println!("{}", i);
    }
}

Measured memory_bytes: 12428
#include <stdio.h>
#include <string.h>
#include <math.h>

long long make_burger(int n, long long x){
  if(n == 0){
    return 1;
  }
  long long len = (1LL << (n + 1) ) - 3;
  long long num = (1LL << n) - 1;
  if(x == 1){
    return 0;
  }else if(x <= len + 1){
    return make_burger(n - 1,x - 1);
  }else if(x == len + 2){
    return num + 1;
  }else if(x <= (len + 1) * 2){
    return num + 1 + make_burger(n - 1,x - len - 2);
  }else{
    return num * 2 + 1;
  }
}

int main(void){
  int n;
  long long x;
  long long ans;
  
  scanf("%d",&n);
  scanf("%lld",&x);

  printf("%lld\n",make_burger(n,x) );
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);



    string s;
    cin>>s;
    
    if(s[0]==s[1] or s[1]==s[2] or s[2]==s[3])
    {
        cout<< "Bad";
    }
    else
    {
        cout<< "Good";
    }
    


    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

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

    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    for (int i = 0; i < h; i++) cin >> s[i];
    int col[h], cnt[h];
    int res = h * w, tmp, flag;
    for (int mask = 0; mask < (1 << (h - 1)); mask++) {
        col[0] = 0;
        tmp = 0;
        for (int i = 1; i < h; i++) {
            col[i] = col[i - 1];
            if (mask & (1 << (i - 1))) {
                col[i]++;
                tmp++;
            }
        }
        memset(cnt, 0, sizeof(cnt));
        for (int i = 0; i < h; i++) {
            if (s[i][0] == '1') cnt[col[i]]++;
        }
        for (int i = 0; i < h; i++) {
            if (cnt[i] > k) {
                tmp = h * w;
                break;
            }
        }
        if (tmp == h * w) continue;
        for (int j = 1; j < w; j++) {
            flag = 0;
            for (int i = 0; i < h; i++) {
                if (s[i][j] == '1') cnt[col[i]]++;
            }
            for (int i = 0; i < h; i++) {
                if (cnt[i] > k) {
                    tmp++;
                    flag = 1;
                    break;
                }
            }
            if (flag) {
                memset(cnt, 0, sizeof(cnt));
                for (int i = 0; i < h; i++) {
                    if (s[i][j] == '1') cnt[col[i]]++;
                }
                for (int i = 0; i < h; i++) {
                    if (cnt[i] > k) {
                        tmp = h * w;
                        break;
                    }
                }
                if (tmp == h * w) continue;
            }
        }
        res = min(res, tmp);
    }
    cout << res << "\n";
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int [] values = new int[n * 2];
        for (int i = 0; i < n * 2; i++) {
            values[i] = input.nextInt();
        }
        Arrays.sort(values);
        int sum = 0;
        for (int i = 1; i < n * 2; i+=2) {
            sum += Math.min(values[i], values[i - 1]);
        }
        System.out.println(sum);
    }
}


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

using ll = long long int;

int main(int argc, char *argv[])
{
	ll N, K;
	std::cin >> N >> K;
	std::vector<ll> A(N, 0);

	for (ll i = 0;i < K; ++i)
	{
		ll d;
		std::cin >> d;
		for (ll j = 0;j < d;++j)
		{
			ll idx = 0;
			std::cin >> idx;
			A[idx-1]++;
		}
	}

	ll idx = 0;
	for (ll i = 0;i < N;++i) if (A[i] == 0) { ++idx; }

	std::cout << idx << std::endl;

	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 
  int N, K;
  cin >> N >> K;
  double ans = 0.0;
  for (int i = 1; i <= N; i++) {
	int score = i;
    double temp = (1.0 / N);
    while (score < K) {
      temp /= 2;
	  score *= 2;      
    }
    ans += temp;
  }
  CST(12);
  cout << ans << endl;
}

    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans,b[105];
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++) scanf("%d",&b[i]);
	for (int i=1;i<n-1;i++) ans+=min(b[i],b[i+1]);
	printf("%d",ans+b[1]+b[n-1]);
}

Measured memory_bytes: 256
n = int(input())
A = [int(input()) for _ in range(n)]

A.sort()

if n%2 == 0:
    ans = A[n//2]-A[n//2-1]
    m = A[n//2]-A[n//2-1]
    for i in range(n):
        if i == n//2-1 or i == n//2:
            continue
        else:
            if i <= n//2:
                ans += m-2*A[i]
            else:
                ans += 2*A[i]-m
else:
    m = A[n//2]
    ans1 = m-A[n//2-1]
    for i in range(n):
        if i == n//2-1 or i == n//2:
            continue
        else:
            ans1 += 2*abs(A[i]-m)
    m = A[n//2]
    ans2 = A[n//2+1]-m
    for i in range(n):
        if i == n//2+1 or i == n//2:
            continue
        else:
            ans2 += 2*abs(A[i]-m)
    ans = max(ans1, ans2)
print(ans)


Measured memory_bytes: 81120
#include<stdio.h>
int main()
{
  long long int n,k,sum=0,temp;
  scanf("%lld %lld",&n,&k);
  long long int arr[n];
  for(long long int i=0;i<n;i++)
  {
    scanf("%lld",&arr[i]);
  }
  for(long long int i=0;i<k;i++)
  {
    sum=sum+arr[i];
  }
  temp=sum;
  for(long long int i=k;i<n;i++)
  {
    int p=i/k;
    sum=sum+arr[i];
    sum=sum-arr[i-k];
    if(sum>temp)
    {
      printf("Yes\n");
      temp=sum;
    }else{
        temp=sum;
      printf("No\n");
    }
  }
  return 0;
}


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

int main(void)
{
int x=0,n,i;
int a[21];

scanf("%d",&n);

for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}

for(i=2;i<n;i++)
{
if(a[i-1]>a[i]&&a[i+1]<a[i])
{
x=x+1;
}
if(a[i+1]>a[i]&&a[i-1]<a[i])
{
x=x+1;
}
}

printf("%d",x);

return 0;
}


Measured memory_bytes: 128
import itertools

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

B = []

for i in range(K):
    A = []
    d = int(input())
    A = list(map(int,input().split()))
    for y in A:
        B.append(A)

B = itertools.chain.from_iterable(B)
B = set(B)
print(N - len(B))

Measured memory_bytes: 9272
x1, y1, x2, y2 = STDIN.gets.chomp.split(" ")
x1, y1, x2, y2 = [x1.to_f, y1.to_f, x2.to_f, y2.to_f]

dx = x2 - x1
dy = y2 - y1

dx2 = dx * dx
dy2 = dy * dy

p Math.sqrt(dx2 + dy2)


Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e3+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
ll arr[MAXN];
ll dp[MAXN][MAXN];
bool done[MAXN][MAXN];
ll d(int l, int r){
    if(l == r + 1){
        return 0;
    }
    if(done[l][r]) return dp[l][r];
    done[l][r] = 1;
    if(r == l){
        return dp[l][r] = arr[r];
    }else{
        ll ans1 = min(arr[l] - arr[r] + d(l + 1, r - 1), arr[l] - arr[l + 1] + d(l + 2, r));
        ll ans2 = min(arr[r] - arr[l] + d(l + 1, r - 1), arr[r] - arr[r - 1] + d(l, r - 2));
        return dp[l][r] = max(ans1, ans2);
    }
}




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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    
    cout<<d(0, n - 1);
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 78592
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n,k;
    cin >> n >> k;
    int ret = n % k == 0 ? 0 : 1;
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;

	int n;
	cin>>n;

	vector<int>a(n);

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

	sort(rall(a));

	int tot=0;

	int id=0;

	for(int i=0;i<n-1;i++)
	{
		tot+=a[id];
		if(i%2==0)
		{
			id++;
		}
	}
	cout<<tot<<endl;
	

}

Measured memory_bytes: 4716