akhauriyash/Code-Regression huggingface dataset:
from collections import Counter

def solve(n, V):
    if V.count(V[0]) == n:
        return n // 2
    return min(
        n - oc - ec
        for o, oc in Counter(V[0::2]).most_common(2)
        for e, ec in Counter(V[1::2]).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))


Measured memory_bytes: 15588
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
*A, = map(lambda x: -int(x), input().split())
heapify(A)
for _ in range(M):
    x = heappop(A)
    x = -(-x//2)
    heappush(A, x)
print(-sum(A))

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

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String str = br.readLine();
		String strAry[] =str.split(" ");
		int x=Integer.parseInt(strAry[0]);
		int y=Integer.parseInt(strAry[1]);
		System.out.println(x*y+" "+(2*x+2*y));
	}
}

Measured memory_bytes: 24312
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int> (D));
    for (auto& v : X) {
        for (int& x : v) cin >> x;
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i >= j) continue;
            int diff = 0;
            for (int k = 0; k < D; k++) {
                int t = abs(X[i][k] - X[j][k]);
                diff += t * t;
            }
            ans += (diff == (int)sqrt(diff) * sqrt(diff));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

const int maxn = 3002;
const int mo = 1e9 + 7;

int n;
string s;

long long f[maxn][maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	cin >> s;

	f[1][1] = 1;
	for (int i = 2; i <= n; ++i)
		if (s[i-2] == '<') {
			for (int j = 2; j <= i; ++j) {
				f[i][j] = (f[i][j-1] + f[i-1][j-1]) % mo;
			}
		} else {
			for (int j = i-1; j >= 1; --j) {
				f[i][j] = (f[i][j+1] + f[i-1][j]) % mo;
			}
		}

	long long ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += f[n][i];

	ans %= mo;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 68992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1000005,mod=998244353;
ll fac[N],ni[N],ans,n,k;
inline int ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
inline ll c(int a,int b){
	return a>=b?fac[a]*ni[b]%mod*ni[a-b]%mod:0;
}
signed main(){
	n=read(); k=read();
	for(int i=fac[0]=1;i<N;i++)fac[i]=fac[i-1]*i%mod; ni[N-1]=ksm(fac[N-1],mod-2);
	for(int i=N-1;i;i--)ni[i-1]=ni[i]*i%mod; //cout<<c(4,2)<<" "<<fac[3]<<" "<<ni[3]<<endl;
	for(int i=max((k+1)/2,n);i<=k;i++){
		int r=i,b=k-i,t=r-n+1;
		if(r==b)b--;
		ans=(ans+c(r+b,r)-c(r+b,r+t))%mod;
	}
	cout<<(ans+mod)%mod<<endl;
}
/*
10 5 5
*/

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
int arr[MAXX];
void trozen()
{
   int a,b;
   cin>>a>>b;
   cout<<(a*b)<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 3648
def resolve():
	s = input()
	a = float('inf')
	z = 0
	for i in range(len(s)):
		if s[i] == 'A':
			a = min(a, i)
		if s[i] == 'Z':
			z = max(z, i)
	print(z - a + 1)
resolve()

Measured memory_bytes: 40352
#include <iostream>                                             
#include <cstdio>                                               
using namespace std;                                            
                                                                
int main(void) {                                                
  int QQ;                                                       
  for (int i=1; i<=9; i++) {                                    
    for (int j=1; j<=9; j++) {                                  
      QQ = i*j;                                                 
      printf("%dx%d=%d\n", i, j, QQ);                           
    }                                                           
  }                                                             
  return 0;                                                     
}                                                               
                             

Measured memory_bytes: 3120
L,R=map(int,input().split())

l=L%2019
r=R%2019

ans=0

if R-L<2019 and l<r:
    D=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            D.append((i*j)%2019)
    ans=min(D)

print(ans)

Measured memory_bytes: 75412
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int A = Integer.parseInt(sc.next());
			int B = Integer.parseInt(sc.next());
			int K = Integer.parseInt(sc.next());
			List<Integer> l = new ArrayList<Integer>();
			for(int i = 1; i <= Math.min(A, B); i++) {
				if(A % i == 0 && B % i == 0) {
					l.add(0, i);
				}
			}
			System.out.println(l.get(K - 1));
		} // Scanner Close
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

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;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main(){
    int x;
    cin >> x;
    int sum = 0;
    int res;
  	int i=0;
    while(true){
        sum += i;
        if (sum >= x){
            res = i;
            break;
        }
      i++;
    }
    cout << res << endl;
}

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

using namespace std;

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

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int a[] = new int[n];
		for (int i=0;i<n;i++)
			a[i] = Math.abs(sc.nextInt()-x);
		
		int d = a[0];
		for (int i=1;i<n;i++) {
			d = gcd(d,a[i]);
		}
		System.out.println(d);
		
	}

	private static int gcd(int a, int b) {
		return b==0?a:gcd(b,a%b);
	}

}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

int mod=1000000007;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int Gcd(int x,int y)              //最大公約数
{
  int large = max(x,y);
  int small = min(x,y);

  while(small!=0){
      int amari =large%small;
      large = small;
      small = amari;  
  }
  return large;
}


//メイン関数--------------------------------------------



int main(){


int k;
cin>>k;
string s;
for(int i=0;i<k;i++){
    s+="ACL";
}
cout<<s<<endl;


}


Measured memory_bytes: 3720
def solve():
    
    N = int(input())
    H = list(map(int, input().split()))
    result = []
    p = 0
    q = 0
    
    for i in range(N-1):     
        if H[i] >= H[i+1]:
            q += 1
        else:
            p = max(p, q)
            q = 0
    p = max(p, q)
    print(p)

solve()

Measured memory_bytes: 14252
n=int(input())
h_list=list(map(int,input().split()))
cnt=0
mx=0
i=0
while i<len(h_list):
    if mx>=(len(h_list)-i):
        break
    num=i
    cnt=0
    for j in range(num,len(h_list)-1):
        if h_list[j]>=h_list[j+1]:
            cnt+=1
        else:
            i=j
            break
    i+=1
    if cnt>mx:
        mx=cnt
print(mx)

Measured memory_bytes: 14252
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] array = br.readLine().split(" ");
        int n = Integer.parseInt(array[0]);
        int m = Integer.parseInt(array[1]);
        int[][] a = new int[n][m];
        int[] b = new int[m];
        for(int i=0;i<n;i++){
            array = br.readLine().split(" ");
            for(int j=0;j<m;j++){
            	a[i][j] = Integer.parseInt(array[j]);
            }
        }
        for(int i=0;i<m;i++){
        	b[i] = Integer.parseInt(br.readLine());
        }
        for(int i=0;i<n;i++){
        	int c=0;
        	for(int j=0;j<m;j++){
        		c+=a[i][j]*b[j];
        	}
        	System.out.println(c);
        }
	}
}

Measured memory_bytes: 22652
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
	int n;
	char buf[100][3],wk[3];
	char s[4][3]={"lu","ru","ld","rd"};
	int i,j,k;
	int data[100],cnt;
	while(1)	{
		scanf(" %d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	{
			scanf("%s",buf[i]);
		}
		cnt=0;
		for(i=1;i<n;i++)	{
			if(strcmp(buf[i-1],"lu")==0 && strcmp(buf[i],"ru")==0)	cnt++;
			if(strcmp(buf[i-1],"ru")==0 && strcmp(buf[i],"lu")==0)	cnt++;			
			if(strcmp(buf[i-1],"ld")==0 && strcmp(buf[i],"rd")==0)	cnt++;				
			if(strcmp(buf[i-1],"rd")==0 && strcmp(buf[i],"ld")==0)	cnt++;	
		}
		printf("%d\n",cnt);
	}
	return 0;
}


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

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

b = [0 for i in range(10**5*1)]

for i in range(n):
    b[a[i]] += 1
if n % 2 == 0:
    if all(list(map(lambda x:x==2,b[1:n+1:2]))):
        print(2**(n//2)%(10**9+7))
    else:
        print(0)

else:
    if all(list(map(lambda x:x == 2,b[2:n+1:2]))) and b[0] == 1:
        print(2**(n//2)%(10**9+7))
    else:
        print(0)


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

typedef long long ll;
typedef pair<int,int> pint;
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());


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

  vint b(n,0);
  
  rep(i,n){
    char c;cin >> c;
    if(c=='R')b[i]++;
  }


  int ltar=b[0],rtar=b[n-1];
  int l=0,r=n-1;

  rep(i,k+1){
    while(b[l]==ltar)l++;
    while(b[r]==rtar)r--;
    if(r<l&&i!=k){
      r=-1;
      break;
    }
    ltar=b[l];rtar=b[r];
  }
  vint a(n);
  rep(i,l-1)a[i]=b[0];
  repi(i,r+1,n)a[i]=b[n-1];
  repi(i,l,r+1){
    if(k%2)a[i]=abs(b[i]-1);
    else a[i]=b[i];
  }
//  rep(i,n)cout << a[i];
//  cout << endl;
  int ans=0;
  rep(i,n){
    int tar=a[i]?i-1:i+1;
    if(tar<0||n-1<tar)continue;
    if(a[i]==a[tar])ans++;
  }
  cout << ans << endl;


}


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

long long N, S, L = 1, A[309], dp[309][99999], dp2[309][99999], mod = 998244353;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) { cin >> A[i]; S += A[i]; }
	dp[0][0] = 1; dp2[0][0] = 1;
	for (int i = 0; i < N; i++) {
		L *= 3; L %= mod;
		for (int j = 0; j <= S; j++) {
			if (dp[i][j] == 0) continue;
			dp[i + 1][j] += 2LL * dp[i][j]; dp[i + 1][j] %= mod;
			dp[i + 1][j + A[i + 1]] += dp[i][j]; dp[i + 1][j + A[i + 1]] %= mod;
			dp2[i + 1][j] += 1LL * dp2[i][j]; dp2[i + 1][j] %= mod;
			dp2[i + 1][j + A[i + 1]] += dp2[i][j]; dp2[i + 1][j + A[i + 1]] %= mod;
		}
	}
	long long L1 = 0; for (int i = (S + 1) / 2; i <= S; i++) L1 += dp[N][i];
	long long L2 = 0; if (S % 2 == 0) L2 = dp2[N][S / 2];
	cout << (L - 3LL * L1 + 3LL * L2 + mod * mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 471296
#include<stdio.h>
int min(int a,int b){
  if(a<b)
    return a;
  else
    return b;
}
int main(){
  int a,b,c;
  scanf("%d %d %d", &a,&b,&c);
  int e=a*b;
  printf("%d",min(e,c));
  return 0;
}

Measured memory_bytes: 2148
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main(void) {
   char a;
   scanf("%c", &a);
   switch (a) {
      case 'A':
         printf("T\n");
         break;
      case 'T':
         printf("A\n");
         break;
      case 'G':
         printf("C\n");
         break;
      case 'C':
         printf("G\n");
         break;
   }
   return 0;
}


Measured memory_bytes: 128
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func pow(a, b int) (result int64) {
	result = 1
	for i:=int64(0);i<int64(b);i++{
		result = (result * int64(a))%1000000007
	}
	return
}

var rexp *regexp.Regexp
var memo map[string]int64

func rec(last3 string,n int) int64{
	if n<=0 {
		return 1
	}
	key := fmt.Sprintf("%s%d",last3,n)
	memoValue, exits := memo[key]
	if exits {
		return memoValue
	}
	sum := int64(0)
	for _,c := range []string{"A","C","G","T"} {
		last4 := last3 + c
		if !rexp.Match([]byte(last4)){
			sum += rec(last4[1:4],n-1)
		}
	}
	sum = sum%1000000007
	memo[key] = sum
	return sum
}

func main() {
	io := NewIo()
	defer io.Flush()
	n := io.NextInt()
	/*
	ダメなパターンは
	AGC
	A?GC
	GAC
	ACG
	AG?C
	が含まれるもの
	*/
	sum := int64(0)
	rexp = regexp.MustCompile("(AGC|GAC|ACG|A.GC|AG.C)")
	memo = map[string]int64{}
	for _,c1 := range []string{"A","C","G","T"} {
		for _,c2 := range []string{"A","C","G","T"} {
			for _, c3 := range []string{"A", "C", "G", "T"} {
				str := c1+c2+c3
				if !strings.Contains(str,"AGC") &&
					!strings.Contains(str,"GAC") &&
					!strings.Contains(str,"ACG") {
					sum += rec(str,n-3)
				}
			}
		}
	}
	io.PrintLn(sum%1000000007)
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  int A = 0, B = 0;
  rep(i, n) if (!(i % 2)) A += v.at(i);
  rep(i, n) if ( (i % 2)) B += v.at(i);
  cout << A - B << endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const int MAX=100001;
const double EPS=1e-10;
vector<int> forest[100010];
vector<int> tree[100010];
bool visited[100010];
int a[100010];
void dfs(int now,int idx){
    visited[now]=true;
    for(auto e:forest[now]){
        if(visited[e]){
            continue;
        }
        tree[idx].push_back(a[e]);
        dfs(e,idx);
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    if(m==n-1){
        cout<<0<<endl;
        return 0;
    }
    if(n<2*(n-m-1)){
        cout<<"Impossible"<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        cin>>a[i];
        visited[i]=false;
    }
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        forest[x].push_back(y);
        forest[y].push_back(x);
    }
    int id=0;
    for(int i=0;i<n;i++){
        if(visited[i]){
            continue;
        }
        tree[id].push_back(a[i]);
        dfs(i,id);
        id++;
    }
    ll ans=0;
    int c=2*(n-m-1);
    priority_queue<int,vector<int>,greater<int>> q;
    for(int i=0;i<id;i++){
        sort(tree[i].begin(),tree[i].end());
        for(int j=0;j<(int)tree[i].size();j++){
            if(j==0){
                ans+=(ll)tree[i][j];
                
                c--;
                continue;
            }
            q.push(tree[i][j]);
        }
    }
    for(int i=0;i<c;i++){
        ans+=(ll)q.top();
        q.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9848
/* ABC116 */
/* C */
#include <iostream>
#include <vector>
using namespace std;

int main(){

    int n;
    int ans=0, active=0;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];

    /*
    コストを先に足していっているイメージ。次にきた花の高さになる為に必要なコストを見積もっている。
    当然、今の高さより低い花がきたら、コストはかからないので、何もしない.
    このアルゴリズムの発想の肝としては、「何に対してコストがかかるのか」を定義するのは当然だが、
    処理の方向をどう見るのかも大切な感じ。自分は範囲に水やりができると聞いて、左右ではなく正面から
    配列を捉えていた。2次元で捉えていた。しかし、これは1次元で捉えられるし、その方がシンプル。
    ex) 1 2 2 1
    1. 最初はactive=0なので、最初の花 h=1 がactiveにセットされる
    2. 2番目はh=2なので、elseに入る。h(=2) - active(=1)が回数に追加され、activeが現在の花になる
    (仮に前回以下のhだった場合は、activeが切り替わるだけで終わる. なぜこれでよいのかというと、水やりは
    範囲をして一度に複数の花にかけられるので、同値以下の花は同時に水をあげるとして次に進めばよい.
    しかし自分より大きな花がくると、その花に必要な水やりの回数が異なるので、activeになっている範囲のみで
    水やりを完了させる
    )
    */
    for (int i=0; i<n; i++){
        if (active >= a[i]){
            active = a[i];
        }
        else{
            ans += a[i] - active;
            active = a[i];
        };
    };

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int A,B,C,X,i,j,k,cnt=0;
	scanf("%d %d %d %d",&A,&B,&C,&X);
	int a=A<X/500?A:X/500,b=B<X/100?B:X,c=C<X/50?C:X/50;
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=c;k++){
				if(X==500*i+100*j+50*k){cnt++;}
			}
		}
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int i, j, S[10000], T[500], n, q, cnt=0;
  scanf("%d", &n);
  if(n > 0 && n <= 10000){
    for(i = 0; i < n; i++)
      scanf("%d", &S[i]);

    scanf("%d", &q);
    if(q > 0 && q <= 500){
      for(i = 0; i < q; i++)
	scanf("%d", &T[i]);

      for(j = 0; j < q; j++){
	i = 0;
	S[n] = T[j];
	while(S[i] != T[j])
	  i++;
	if(i != n)
	  cnt++;
      }
      printf("%d\n", cnt);
    }
  }
  return 0;
}



Measured memory_bytes: 2104
<?php
error_reporting(0);
$N = trim(fgets(STDIN));
$D = explode(" ",trim(fgets(STDIN)));
$M = trim(fgets(STDIN));
$T = explode(" ",trim(fgets(STDIN)));
//list($N,$M,$K) = explode(" ",trim(fgets(STDIN)));
foreach($D as $d) {
  if (isset($chk[$d])) {
    $chk[$d]+=1;
  }
  else {
    $chk[$d]=1;
  }
}
foreach($T as $t) {
  if (array_key_exists($t,$chk)) {
    if ($chk[$t]==0) {
      printf("NO\n");
      exit;
    }
    $chk[$t]--;
  }
  else {
    printf("NO\n");
    exit;
  }
}
printf("YES\n");


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

int main() {int a,b,c,d,e,f,g,h,i,j,n,p;
            cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>n;
            j=0;
            vector<int> vec(n);

            while(j<n){
              cin>>p;
              vec.at(j)=p;
              j++;}
            
            for (int k = 0; k < n; k++) {if(vec.at(k)==a){a=1000;
                                                         break;}

}
            for (int k = 0; k < n; k++) {if(vec.at(k)==b){b=1000;
                                                         break;}

}for (int k = 0; k < n; k++) {if(vec.at(k)==c){c=1000;
                                                         break;}

}for (int k = 0; k < n; k++) {if(vec.at(k)==d){d=1000;
                                                         break;}

}for (int k = 0; k < n; k++) {if(vec.at(k)==e){e=1000;
                                                         break;}

}for (int k = 0; k < n; k++) {if(vec.at(k)==f){f=1000;
                                                         break;}

}for (int k = 0; k < n; k++) {if(vec.at(k)==g){g=1000;
                                                         break;}

}for (int k = 0; k < n; k++) {if(vec.at(k)==h){h=1000;
                                                         break;}

}for (int k = 0; k < n; k++) {if(vec.at(k)==i){i=1000;
                                                         break;}}
                              if(a==1000&&b==1000&&c==1000){cout<<"Yes"<<endl;}
                               else if(d==1000&&e==1000&&f==1000){cout<<"Yes"<<endl;}
                               else if(g==1000&&h==1000&&i==1000){cout<<"Yes"<<endl;}
                               else if(a==1000&&d==1000&&g==1000){cout<<"Yes"<<endl;}
                               else if(b==1000&&e==1000&&h==1000){cout<<"Yes"<<endl;}
                               else if(c==1000&&f==1000&&i==1000){cout<<"Yes"<<endl;}
                               else if(a==1000&&e==1000&&i==1000){cout<<"Yes"<<endl;}
                               else if(g==1000&&e==1000&&c==1000){cout<<"Yes"<<endl;}
                              else{cout<<"No"<<endl;}

            
  
}


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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    int N;
    cin >> N;
    long long int a[N],sum=0,summ[N],ans=0,tmp=0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
        summ[i] = sum;
    }

    for(int i = 0; i < N-1; i++) {
        tmp = abs(summ[i]-(sum-summ[i]));
        if(i == 0) {
            ans = tmp;
        }else {
            ans = min(ans,tmp);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> A(N); cin >> A;
    sort(ALL(A));
    reverse(ALL(A));
    priority_queue<ll> pq;
    pq.emplace(A[0]);
    ll ans=0;
    for (int i=1;i<N;++i){
        ll v=pq.top(); pq.pop();
        ans+=v;
        pq.emplace(A[i]); pq.emplace(A[i]);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 6892
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			int m = cin.Int();

			int max = m / n;
			int ans = 1;
			for (int i = max; i >= 1; i--) {
				if (m % i == 0) {
					ans = i;
					break;
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
int n,f;
long long ans;
int main()
{
    cin>>n;
    for(int i=2;i<=55555;i++)
   	{
    	f=false;
    	for(int j=2;j*j<=i;j++)
     	{
      		if(i%j==0)
      		{
        		f=true;
        		break;
      		}
   		}
   		if(!f && i%10==1)
     	{
        	cout<<i;
        	ans++;
        	if(ans==n) break;
         	else cout<<" ";
     	}
   	}
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 if(A + B == C + D){
  cout << "Balanced" << endl;
 }
  else if(A + B > C + D){
    cout << "Left" << endl;
  }
  else if(A + B < C + D){
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
c = []
for i in range(h):
    for j in range(w):
        cost = 0
        for k in range(h):
            for l in range(w):
                cost += a[k][l]*min(abs(k-i),abs(l-j))
        c.append(cost)
print(min(c))


Measured memory_bytes: 5608
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int n;
int l[100005];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }
  sort(l, l+n);
  ll ret = 0;
  vector<int> four;
  vector<int> two;
  for(int i = 0; i < n;) {
    int j = i+1;
    while(j < n && l[i] == l[j]) {
      j++;
    }
    if(j-i >= 4) {
      four.push_back(l[i]);
    }
    if(j-i >= 2) {
      two.push_back(l[i]);
    }
    i = j;
  }
  if(four.size() > 0) {
    ret = max(ret, four[four.size()-1] * (ll)four[four.size()-1]);
  }
  if(two.size() > 1) {
    ret = max(ret, two[two.size()-1] * (ll)two[two.size()-2]);
  }
  printf("%lld\n", ret);
}


Measured memory_bytes: 1024
#include <cstdio>
int N, K, l, r, x, c, a[1000009], v[1000009], p[1000009]; char ch, s[19];
int main() {
	scanf("%d %d\n", &N, &K);
	for (int i = 0; i < N; i++) {
		ch = getchar_unlocked();
		while (48 <= ch && ch <= 57) a[i] = a[i] * 10 + ch - 48, ch = getchar_unlocked();
	}
	for (int i = 0; i < K; i++) {
		while (l != r && v[r - 1] >= a[i]) r--;
		v[r] = a[i], p[r++] = i;
	}
	for (int i = K; i <= N; i++) {
		x = v[l]; c = 0;
		while (x > 0) s[c++] = x % 10 + 48, x /= 10;
		while (c--) putchar_unlocked(s[c]);
		putchar_unlocked(i == N ? '\n' : ' ');
		if (p[l] == i - K) l++;
		while (l != r && v[r - 1] >= a[i]) r--;
		v[r] = a[i], p[r++] = i;
	}
	return 0;
}


Measured memory_bytes: 14340
#include<cstdio>

using namespace std;

int main(){
	for(int b,r,g,c,s,t;scanf("%d%d%d%d%d%d",&b,&r,&g,&c,&s,&t),b||r||g||c||s||t;){
		int bonusTime=5*b+3*r;
		int addedCoin=15*b+15*r+7*g+2*c+15*(bonusTime);
		int paidCoin=3*(t-s-bonusTime)+2*bonusTime;
		printf("%d\n",100+addedCoin-paidCoin);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int a[n],b;
int ans=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
cin>>b;
ans+=max(0,a[i]-b);
}
cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
long long a[200010];
long long b[200010];
int main(){
    int c;
    cin>>c;
    long long s=0;
    for(int i=0;i<c;i++){
        cin>>a[i];
        if(i==0)
            b[i]=a[i];
        else
            b[i]=b[i-1]+a[i];
        s=s+a[i];
    }
    long long m;
    if(b[0]>s-b[0])
        m=b[0]+b[0]-s;
    else
        m=s-b[0]-b[0];
    for(int i=1;i<(c-1);i++){
        if(m>abs(s-b[i]-b[i]))
        m=abs(s-b[i]-b[i]);
    }
    cout<<m<<endl;
    return 0;
} 

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

const long long INF = 1LL << 60;
const ll MOD = ll(1e9)+7;


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

ll vector_finder(vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  if (itr == vec.end()) {
    return -1;
  }
  size_t index = std::distance( vec.begin(), itr );
  return index;
}

bool has_key_using_find(unordered_map<ll, string> &m, ll n){
    if (m.find(n) == m.end()){
        return false;
    }
    else{
        return true;
    }
}

ll enum_divisors(ll N) {
    ll count = 0;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            count++;
            if (N/i != i) count++;
        }
    }
    return count;
}


vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

bool IsPrime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}


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

    vector<ll> A(N);

    for (ll i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    sort(A.begin(), A.end(), greater<ll>());

    for (ll i = 0; i < (N-1)/2; i++) {
        ans += A.at(i);
    }


    if (N%2 == 0) {
        for (ll i = (N+1)/2; i < N-1; i++) {
            ans += A.at(i-((N-1)/2));
        }
        ans += A.at((N-1)/2);
    } else {
        for (ll i = (N+1)/2; i < N; i++) { 
            ans += A.at(i-((N-1)/2));
        }
    }
    
    
    
    
    

    cout << ans << endl;


    return 0;
}

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

int main() {
  int N, K, A;
  cin >> N >> K;
  A = 1;
  
  for (int i = 0; i < N; i++) {
    if (A * 2 - A < K) {
      A *= 2;
    }
    else {
      A += K;
    }
  }
  cout << A << endl;
}

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

#define MAX 86400

int main(){
  int n, t[MAX+1];
  while(cin >> n, n){
    memset(t, 0, sizeof(t));
    int H1, H2, M1, M2, S1, S2;
    for(int i = 0 ; i < n ; i++){
      scanf("%d:%d:%d %d:%d:%d", &H1, &M1, &S1, &H2, &M2, &S2);
      t[H1*3600+M1*60+S1]++, t[H2*3600+M2*60+S2]--;
    }
    int ans = 0;
    
    for(int i = 1 ; i <= MAX ; i++){
      t[i] += t[i-1];
      ans = max(ans, t[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	5e5;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN];ll vis[MAXN]={};
/*
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/
// <------------- Declare Variables Here ------------> //



ll T = 1;
ll n, x, k, m, r, sum = 0, a, b;
string s;

// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> a >> b;
	ll rem = n%(a+b);
	ll quo = n/(a+b);
	ll ans = quo * a + min(rem,a);
	cout<<ans;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 15376
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n; cin >> n;
	string st;
	cin >> st;
	string a = st.substr(n/2);
	string b = st.substr(0, n/2);
	if(a==b)
		cout << "Yes\n";
	else
		cout << "No\n";	
}


Measured memory_bytes: 256
# from sys import exit
while(True):
    N = int(input())
    if N == 0:
        break
    L = []
    for i in range(N):
        r = [int(n) for n in input().split()]
        time = sum([r[i]*60 + r[i+1] for i in range(1, 9, 2)])
        L.append((r[0], time))
        # print(abs(22- w/((h/100)**2)))
    L = sorted(L, key=lambda x: x[1])
    print(L[0][0])
    print(L[1][0])
    print(L[-2][0])



Measured memory_bytes: 6332
#include<bits/stdc++.h>
using namespace std;
int main(){
    double n,m,d;
    cin >> n >> m >> d;
    if(d==0){
      cout << fixed << setprecision(10) << (m-1)/n << endl;
    }
    else{
      cout <<fixed << setprecision(10) << (m-1)*2*(n-d)/(n*n) << endl;
    }
}

Measured memory_bytes: 256
def get_all_index(a, value)
  index = []
  _a = a.dup
  while _a.include?(value)
    next_i = _a.index(value)
    index << next_i
    _a[next_i] = nil
  end
  index
end

n = gets.to_i
virgin = true

n.times do
  puzzle = [] # Taro's answer
  errata = [] # errata for Taro
  
  puts "" unless virgin

  9.times do
    puzzle << gets.split.map(&:to_i)
    errata << Array.new(9, true)
  end

  # checking row and column
  0.upto(8) do |i|
    0.upto(8) do |j|
      (j+1).upto(8) do |k|
        if puzzle[i][j] == puzzle[i][k]
          errata[i][j] = false
          errata[i][k] = false
        end
        if puzzle[j][i] == puzzle[k][i]
          errata[j][i] = false
          errata[k][i] = false
        end
      end
    end
  end
  
  # checking box
  box_index = []
  -1.upto(1) do |i|
    -1.upto(1) do |j|
      box_index << [i, j]
    end
  end
  [1,4,7].each do |i|
    [1,4,7].each do |j|
      cb = []
      cb_index = []
      box_index.each do |b|
        cb_index << [b[0] + i, b[1] + j]
        cb << puzzle[b[0] + i][b[1] + j]
      end
      if (temp = cb.uniq.select{ |x| cb.index(x) != cb.rindex(x) }).any?
        temp.each do |m|
          get_all_index(cb, m).each do |i|
            x, y = cb_index[i]
            errata[x][y] = false
          end
        end
      end
    end
  end

  # output
  0.upto(8) do |i|
    0.upto(8) do |j|
      if errata[i][j]
        print " #{puzzle[i][j]}"
      else
        print "*#{puzzle[i][j]}"
      end
      puts "" if j == 8
    end
  end

  virgin = false if virgin
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;


int main() {
    int n;
    cin >> n;
    vector <int> a(n);
    int all_xor = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        all_xor ^= a[i];
    }
    for(int i = 0; i < n; i++) {
        cout << (all_xor ^ a[i]) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

ll n;
vector<ll> ans;

void dfs(ll x){
  ans.pb(x);
  if(x > 3234566667) return;
  dfs(x*10+x%10);
  if(x%10 != 0) dfs(x*10+x%10-1);
  if(x%10 != 9) dfs(x*10+x%10+1);
  return;
}

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

  cin >> n;
  for(ll i = 1; i <= 9; i++){
    dfs(i);
  }
  sort(all(ans));
  cout << ans[n-1] << endl;

  return 0;
}

Measured memory_bytes: 6512
while True:
  a, b = map(int, input().split())
  if a == 0 & b == 0:
    break
  count = 0
  for s in range(2**10):
    arr = [i for i in range(10) if s >> i & 1]
    if len(arr) == a:
      sum = 0
      for i in range(0, len(arr)):
        sum += arr[i]
      if sum == b:
        count += 1
  print(count)


Measured memory_bytes: 5604
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int N, K;
int main() {
  cin >> N >> K;
  int l[N];
  for (int i = 0; i < N; ++i) cin >> l[i];

  int ans = 0;

  sort(l, l + N, greater<int>());

  for (int i = 0; i < K; i++) {
    ans += l[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int x = sc.nextInt();

		if (x == 3 || x == 5 || x == 7) {
			pr.println("YES");
		} else {
			pr.println("NO");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int n; cin >> n;
    vector<int> l(n);
    int mx = 0;
    rep(i, n) {
        cin >> l.at(i);
        mx = max(mx, l.at(i));
    }

    int sum = 0;
    rep(i, n){
       sum += l.at(i); 
    }
    sum -= mx;

    if(mx<sum) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

using namespace std;

int main(void){
int n,m,s[400],l[400],p[400],w[400],dp[400];

cin >> n;
for(int i=0;i<n;i++)
cin >> s[i] >> l[i] >> p[i];

cin >> m;
for(int i=0;i<m;i++)cin >> w[i];

fill(dp,dp+400,-1);
dp[0]=0;

for(int i=1;i<400;i++){
for(int j=0;j<n;j++){
for(int k=s[j];k<=l[j];k++){
if(i-k>=0)dp[i]=max(dp[i],dp[i-k]+p[j]);
}
}
}

for(int i=0;i<m;i++){
if(dp[w[i]]<0){
cout << -1 << endl;
return 0;
}
}


for(int i=0;i<m;i++){
cout << dp[w[i]] << endl;
}

return 0;
}

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int n = int.Parse(In[0]);
            int k = int.Parse(In[1]);
            int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            for (int i = 0; i < n - k; i++)
            {
                if (A[i] < A[k + i]) Console.WriteLine("Yes");
                else Console.WriteLine("No");
            }
        }
    }
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

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

    int cnt = 0;
    int len = s.length();
    for(int i = 0; i < len / 2; i++) {
        if(s[i] != s[len - i - 1]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
#include <functional>
#include <iomanip>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	cout << std::fixed << std::setprecision(10);

	for (;;) {
		int N;

		cin >> N;
		if (cin.fail()) break;

		vector<int> A(N);
		vector<int> B(N);
		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}
		for (int i = 0; i < N; i++) {
			cin >> B[i];
		}
		for (int i = 1; i < N; i++) {
			A[i] += A[i - 1];
		}
		for (int i = N - 2; i >= 0; i--) {
			B[i] += B[i + 1];
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			int x = A[i] + B[i];
			res = max(res, x);
		}
		cout << res << endl;
	}

	return 0;
}


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

#define ll long long
#define ull unsigned long long 

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    ll ss=1;
    for(int i=0; i<n; ++i){
        cin >> a[i];
        if(!(a[i]&1))
            ss *= 2;
    }
    cout << pow(3,n) - ss;
}


Measured memory_bytes: 4140