akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(){
    int A, B, C, K, out;
    cin >> A >> B >> C >> K;

    out = 0;
    while(K>0){
        if(A>0){
            if(A>K){
                out += K;
                K -= K;
                A -= K;
            }
            else{
                out += A;
                K -= A;
                A -= A;
            }
        }
        else if(B>0){
            if(B>K){
                K -= K;
                B -= K;
            }
            else{
                K -= B;
                B -= B;
            }
        }
        else{
            if(C>K){
                out -= K;
                K -= K;
                C -= K;
            }
            else{
                out -= C;
                K -= C;
                C -= C;
            }
        }
    }

    cout << out << endl;
}

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

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

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

    deque<int> dque;
    int f = N%2;

    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(i%2 == f){
            dque.push_back(a);
        }else{
            dque.push_front(a);
        }
    }

    for(int a : dque){
        cout << a << " ";
    }

    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h[5];
    while(true) {
        cin >> h[0];
        if(h[0] == 0) break;
        
        cin >> h[1] >> h[2] >> h[3] >> h[4];
        
        int table[3];
        for(int i = 0; i < 3; i++) {
            table[i] = 0;
        }
        for(int i = 0; i < 5; i++) {
            table[h[i]-1] = 1;
        } 

        int s = table[0] + table[1] + table[2];
        int win, lose;
        if(s != 2) {
            for(int i = 0; i < 5; i++) {
                cout << 3 << endl;
            }
        } else {
            if(table[0] == 0) {
                win = 2;
                lose = 3;
            } else if(table[1] == 0) {
                win = 3;
                lose = 1;
            } else if(table[2] == 0) {
                win = 1;
                lose = 2;
            }
            for(int i = 0; i < 5; i++) {
                if(h[i] == win) {
                    cout << 1 << endl;
                } else {
                    cout << 2 << endl;
                }
            }
        }
    }
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;
//const int MAXN = 200005;

int sg(int g, int id, int k) {
	id = (id % (g + 1) + g + 1) % (g + 1);
	int id_r = ((g + 1) - id) % (g + 1);
//	cout << "At " << g << ' ' << id << ' ' << id_r << '\n';
	
	if (id_r % k == 0) {
		return g - id_r / k;
	}
	if (g / k == 0) {
		return sg(g - 1, k - 1 + id, k);
	}
	
	int ng = g - g / k, head_r = k * (g / k);
	if (id_r > head_r) {
		return sg(ng, -(id_r - head_r), k);
	}
	else {
		int p1 = head_r / k, p2 = id_r / k + 1, between = p1 - p2;
		return sg(ng, head_r - id_r - between, k);
	}
}

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

	int n, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, k;
		cin >> a >> k;
		sum ^= sg(a / k, a % k, k);
	}
	if (sum == 0) {
		cout << "Aoki\n";
	}
	else {
		cout << "Takahashi\n";
	}

	return 0;
}

Measured memory_bytes: 256
N, H = map(int, input().split(' '))
a = []
b = []
for i in range(N):
    temp_a, temp_b = input().split(' ')
    a.append(int(temp_a))
    b.append(int(temp_b))
maxi = a.index(max(a))
sorted_b = sorted(b)[::-1]
i = 0
while(H > 0 and i != N):
    if a[maxi] < sorted_b[i]:
        H -= sorted_b[i]
        i += 1
    else:
        break
left = 0
if H > 0:
    left = (H + a[maxi] - 1) // a[maxi]
print(i + left)


Measured memory_bytes: 12572
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main() {
	ll R;
    cin >> R;

	cout << ((R < 1200) ? "ABC" : ((R < 2800) ? "ARC" : "AGC"))  << endl;
}


Measured memory_bytes: 632
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
p = p[:x]
q = q[:y]
w = p+q+r
w.sort(reverse=True)
print(sum(w[:x+y]))

Measured memory_bytes: 23328
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1024*1024*2+50;
int a[200000+50];
int A[200000+50];
int p[maxn];
int b[200000+50];
int pre[200000+50];
int nx[200000+50];
int n;
long long ans=0;
int main()
{   

    scanf("%d",&n);
    for(int i=1;i<=n;i++)  //区间最长不超过20
    scanf("%d",&A[i]);
    long long zero=0;
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        if(A[i]==0)
        zero++;
        else
        {
            if(zero==1) ans++;
            else
            {
                ans+=(zero*(zero-1))/2;
                ans+=zero;
            }
            
            a[++tot]=A[i];
            pre[tot]=zero;
            zero=0;
        }
    }
    if(zero)
    {
        if(zero==1) ans++;
            else
            {
                ans+=(zero*(zero-1))/2;
                ans+=zero;
            }
    }
    pre[tot+1]=zero;
    n=tot;
    for(int i=1;i<=n;i++)
    {
        b[i]=a[i]^b[i-1];
    }
    for(int i=1;i<=n;i++)
    a[i]=a[i]+a[i-1];
    
    
    for(int i=1;i<=20;i++)
    {
        for(int j=1;j+i-1<=n;j++)
        {
            if((b[i+j-1]^b[j-1])==(a[i+j-1]-a[j-1]))
            {   
              //  printf("%d %d  %d %d %d %d\n",b[i+j-1],b[j-1],a[i+j-1],a[j-1],b[i+j-1]^b[j-1],a[i+j-1]-a[j-1]);
                long long pre0=pre[j];
                long long nx0=pre[i+j];
                ans+=(pre0+1)*(nx0+1);
               // printf("%d %d %d\n",ans,j,i+j-1);
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}   

Measured memory_bytes: 5120
#include <iostream>
using namespace std;
int factorial(int x)
{
    int tmp = x;
    for( int i = 1; i<x;i++){
    tmp = tmp+i;
    }
return tmp;
}
int main(void){
    int n;
    cin >> n;
    if(n>=101||n<=0){
        exit(0);
    }
    cout<<factorial(n);
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    s1=s[:2]
    s2=s[2:]
    l=['01','02','03','04','05','06','07','08','09','10','11','12']
    if s1 in l and s2 in l:
        print('AMBIGUOUS')
    elif s1 in l and s2 not in l:
        print('MMYY')
    elif s1 not in l and s2 in l:
        print('YYMM')
    else:
        print('NA')
resolve()

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

int main(){
    int N;
    std::cin>>N;
    std::vector<int> K(N),P(N);
    for(int i=0;i<N;++i){
        std::cin>>K[i]>>P[i];
    }
    for(int j=0;j<N;++j){
        if(K[j]%P[j]==0)std::cout<<P[j]<<std::endl;
        else std::cout<<K[j]%P[j]<<std::endl;
    }
    return 0;
}

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

using namespace std;
int main() {
	int a, b, h;
	int sqer=0;
	cin >> a >> b >> h;
	if (h%2==0)
	{
		sqer=((a + b)*h) / 2;
	}
	else
	{
		cout << "error" << endl;
	}

	cout << sqer << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second


using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	int ans = 0;
	vector<pair<int, int> > H(N);
	for(int i = 0 ; i < N ; i++){
        cin >> H[i].S >> H[i].F;
	}
	sort(H.begin(), H.end());
	cout << H[0].F + H[0].S;


    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
    int n;
    int x;
    int i;
    int j;
    int l;
    int k;
    int f;
    while(1){
        f = 0;
        scanf("%d%d",&n,&x);
        if(n==0&&x==0){
            break;
        }
        k = 1;
            for(i=k;i<=n;i++){
                for(j=i+1;j<=n;j++){
                    for(l=j+1;l<=n;l++){
                        if(i+j+l==x){
                            //printf("%d %d %d\n",i,j,l);
                            f++;
                        }
                    }
                   //printf("{%d %d %d}\n",i,j,l);
                }
               //printf("[%d %d %d]\n",i,j,l);
            }
        printf("%d\n",f);
    }
    return 0;
}


Measured memory_bytes: 2048
a,b,c,d = list(input())
s = ["+", "-"]

for op1 in s:
    for op2 in s:
        for op3 in s:
            ans = a + op1 + b + op2 + c + op3 + d
            if eval(ans) == 7:
                print(ans + "=7")
                exit()

Measured memory_bytes: 2940
#include<stdio.h>
int print_Yes_No(int x){
  if(x==0)printf("Yes\n");
  if(x==1)printf("No\n");
  return 0;
                 }
int main(){
  int M, a=0, b=0, c=0;
  scanf("%d", &M);
  a=M%10;
  b=((M-a)/10)%10;
  c=((M-a-b*10)/100)%10;
  //printf("%d %d %d",a,b,c);
  if(a==7){
    print_Yes_No(0);}
  else
    if(b==7){
    print_Yes_No(0);}
  else
    if(c==7){
    print_Yes_No(0);}
  else{print_Yes_No(1);}
  return 0;
}

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

using namespace std;

#define FC ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#define deb(x) cerr<<"DEBUG------"<<'\n';cerr<<#x<<"------>";err(x)

template<typename T>
void err(T a){
    cerr<<a<<'\n';
    cerr<<"END OF DEBUG"<<'\n'<<'\n';
}

const long double PI=acos(-1.0);  
const long double eps=1e-6;
const long long maxw=(long long)1e17+(long long)10;

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

/*head------[@cordercorder]*/

const ll maxn=110ll;

ll N,W;
ll w[maxn],v[maxn];
ll maxv,dp[100010];

void solve(){
    for(ll i=1;i<=maxv;i++){
        dp[i]=(ll)1e13;
    }
    for(ll i=1;i<=N;i++){
        for(ll j=maxv;j>=v[i];j--){
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
        }
    }
    ll ans=0ll;
    for(ll i=1;i<=maxv;i++){
        if(dp[i]<=W){
            ans=max(ans,i);
        }
    }
    printf("%lld\n",ans);
}

int main(void){
    scanf("%lld %lld",&N,&W);
    maxv=0;
    for(ll i=1;i<=N;i++){
        scanf("%lld %lld",&w[i],&v[i]);
        maxv+=v[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 1024
h,w,d=map(int,input().split())

pos=[(0,0) for _ in range(h*w)]

for i in range(h):
    for j,a in enumerate(input().split()):
        pos[int(a)-1]=(i,j)

q=int(input())


distances=[0 for _ in range(h*w)]

for i in range(d,h*w):
    a=h*w-i
    i,j=pos[a-1]
    x,y=pos[a+d-1]
    distances[a-1]=distances[a+d-1]+abs(i-x)+abs(j-y)

for _ in range(q):
    l,r=map(int,input().split())
    print(distances[l-1]-distances[r-1])

Measured memory_bytes: 59720
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    int n, m, a[100005] = {}, b[100005] = {};
    ll z = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> a[i];
    sort(a, a + m);
    for (int i = 1; i < m; i++) b[i] = a[i] - a[i - 1];
    sort(b + 1, b + m);
    for (int i = 1; i <= m - n; i++) z += b[i];
    cout << z;
}


Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete


main = cond 1 0 . (>=1000) . sum . zipWith (*) [1,5,10,50,100,500] <$> getInts >>= print


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) {
            p[i] = sc.nextInt();
        }
        if (isOK(p)) {
            System.out.println("YES");
            return;
        }
        for (int i = 0; i <= N - 2; i++) {
            for (int j = i + 1; j <= N - 1; j++) {
                int[] pClone = p.clone();
                int tmp = pClone[i];
                pClone[i] = pClone[j];
                pClone[j] = tmp;
                if (isOK((pClone))) {
                    System.out.println("YES");
                    return;
                }
            }
        }
        System.out.println("NO");
    }

    boolean isOK (int[] array) {
        for (int i = 0; i <= array.length - 2; i++) {
            if (array[i] > array[i + 1]) {
                return false;
            }
        }
        return true;
    }

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



Measured memory_bytes: 22996
import java.util.Scanner;

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

		int[][] dist = new int[n][n];

		for(int i = 0; i < n; i++){
			for(int j =0; j<n; j++){
				if(i==j) dist[i][j] = 0;
				else dist[i][j] = (int)1e9;
			}
		}
		for(int i=0; i<m; i++){
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
			c[i] = sc.nextInt();

			dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
		}

		for(int k=0; k<n; k++){
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					dist[i][j] = Math.min(dist[i][k] + dist[k][j], dist[i][j]);
				}
			}
		}

		int count =0;
		for(int i=0; i<m; i++){
			if(c[i] > dist[a[i]][b[i]]) count++;
		}

		System.out.println(count);
	}
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a.at(i) >> b.at(i);
  
  ll ans = 0;
  for(int i = n - 1; i >= 0; i--){
    if((a.at(i) + ans) % b.at(i) == 0) continue;
    ans += (b.at(i) - ((a.at(i) + ans) % b.at(i)));
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1792
import java.io.*;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        try {
            String str = br.readLine();
            String[] splited_Array = str.split(" ");
            System.out.println(Integer.parseInt(splited_Array[0])*Integer.parseInt(splited_Array[1]) + " " + 2*(Integer.parseInt(splited_Array[0])+Integer.parseInt(splited_Array[1])));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24144
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long a,b=0,c,d,e[1000001],f[1000001];
string a1;
inline long long read(){
	char s;
	long long x,f=1,o=0;
	while(s<'0'||s>'9'){
		if(s=='-'){
			f=-1;
		}
		s=getchar();
	}
	while(s>='0'&&s<='9'){
		o=o*10+s-'0';
		s=getchar();
	}
	return x=o*f;	
}
int main(){
	cin>>a1;
	a=read();
	for(long long i=0;i<a1.length();i++){
		if(a1[i]=='1'){
			b+=1;
			if(b>=a){
				printf("%lld\n",a1[i]-'0');
				return 0;
			}			
		}		
		else{
			c=a1[i]-'0';
			d=1;
			for(long long j=0;j<5000000000000000;j++){
				d*=c;
				b+=d;
				if(b>=a){
					printf("%lld\n",a1[i]-'0');
					return 0;
				}				
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		for(int i = 0; i < n ;i++){
			String[] inputs = reader.readLine().split(" ");
			int[] abc = new int[3];
			for(int j = 0 ; j < abc.length ; j++){
				abc[j] = Integer.parseInt(inputs[j]);
			}
			Arrays.sort(abc);
			if(Math.pow(abc[2], 2)== (Math.pow(abc[0], 2) + Math.pow(abc[1], 2))){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

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

int a[100010];

int main(){
	int n; scanf("%d", &n);
	int maxj = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		maxj = max(maxj, a[i]);
	}
	int minj = 0x3f3f3f3f, pos;
	for (int i = 0; i < n; i++){
		if (abs(a[i] - (maxj + 1) / 2) < minj && a[i] < maxj) minj = abs(a[i] - (maxj + 1) / 2), pos = a[i];
	}
	printf("%d %d\n", maxj, pos);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}



int main() {
    int n;
    cin >> n;
    vector<int>cnt(100000);
    for(int x = 1;x<=100;x++) {
        for(int y = 1;y<=100;y++) {
            for(int z = 1;z<=100;z++) {
                ll tmp = x*x+y*y+z*z+x*y+y*z+z*x;
                cnt[tmp]++;
            }
        }
    }
    for(int i = 1;i<=n;i++) {
        cout << cnt[i] << endl;
    }
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int a,b;
    cin >> a >> b;
    int temp = b;
    int  count =0;
    while (temp>0){
        temp/=10;
        count++;
    }
    int main = a;
    for(int i=0; i<count; i++){
        main *= 10;
    }
    int num = sqrt(main+b);
    if(pow(num,2)==main+b){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 3668
import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] dif = new int[n];
        for(int i = 0; i < n; i++) dif[i] = sc.nextInt();
        Arrays.sort(dif);
        System.out.println(dif[n / 2] - dif[n / 2 - 1]);
    }
}

Measured memory_bytes: 52032
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)

    firstx = -1
    lastz = slen

    for i in range(slen):
        if firstx == -1 and s[i] == 'A':
            firstx = i
        if s[i] == 'Z':
            lastz = i
    
    print(lastz - firstx +1)
    
solve()


Measured memory_bytes: 3512
a=int(input())
b=list(map(int,input().split()))
bmax=max(b)+1
bmin=min(b)
ans=1000000
for i in range(bmin,bmax,1):
  e=0
  for j in b:
    e+=(i-j)**2
  ans=min(ans,e)
print(ans)

Measured memory_bytes: 9116
<?php
	$array = str_split(fgets(STDIN));
	if($array[0] == $array[1] && $array[1] == $array[2]){
		echo 'Yes';
	}else if($array[1] == $array[2] && $array[2] == $array[3]){
		echo 'Yes';
	}else{
		echo 'No';
	}
?>

Measured memory_bytes: 4604
import sys
from itertools import count
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline




def solve(dist, start, goal, moves):
    q = [start]
    c0 = 0
    c1 = 1
    while q:
        nq = []
        while q:
            x = q.pop()
            if x == goal:
                return c0
            if dist[x] < c0:
                continue
            for d,l in moves:
                nx = x+d
                dnx = dist[nx]
                if dnx > c0:
                    dist[nx] = c0
                    q.append(nx)
                elif dnx < 0:
                    for t in l:
                        p = x+t
                        if dist[p] > c1:
                            dist[p] = c1
                            nq.append(p)
        q = nq
        c0 += 1
        c1 += 1
    return -1




if __name__ == '__main__':

    MOVES = (
    ((1, 0), ((2,-1),(2,0),(2,1),(2,2),(1,1))),
    ((-1, 0),((-2,-1),(-2,0),(-2,1),(-2,-2),(-1,-1))),
    ((0, 1), ((1,2),(0,2),(-1,2),(-2,2),(-1,1))),
    ((0, -1), ((1,-2),(0,-2),(-1,-2),(2,-2),(1,-1))),
    )

    H,W = map(int,readline().split())
    start = tuple(map(lambda i:int(i)+1,readline().split()))
    goal = tuple(map(lambda i:int(i)+1,readline().split()))

    H += 4
    W += 4

    dist = [-1]*(W*H)
    convert = lambda x,y: x*W+y

    start = convert(*start)
    goal = convert(*goal)

    i = 2*W+2
    for s in read().split():
        for c in s.decode():
            if c == '.':
                dist[i] = 10**7
            i += 1
        i += 4

    moves = tuple((convert(*d),tuple(convert(*d) for d in l)) for d,l in MOVES)

    print(solve(dist,start,goal,moves))


Measured memory_bytes: 87580
n,*h=map(int,open(0).read().split())

INF=float("inf")
dp=[INF]*(n)
dp[0]=0

for i in range(n):
    try:
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    except:pass
    try:
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
    except:pass
    # if not i-1<0:
    #     dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    # if not i-2<0:
    #     dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))


print(dp[-1])

Measured memory_bytes: 57872
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    int n;
    cin >> n;
    
    map <ll, int> mp;
    rep (i, n) {
        ll a;
        cin >> a;
        mp[a]++;
    }

    vector<ll> use;

    for (auto x: mp) {
        if (x.se >= 2) {
            rep (i, x.se / 2) {
                use.pb(x.fi);
            }
        }
    }

    sort(rrng(use));

    if (use.size() < 2) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = use[0] * use[1];

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


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int s,w;
    string ans;
    cin >> s >> w;
    if(w >= s)ans = "unsafe";
    else ans = "safe";

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3624
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 200000;
int N;
ll A[MAX_N+1];
ll sum[MAX_N+1];

int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  for (int i = 1; i <= N; ++i) sum[i] = sum[i-1] + A[i];

  ll ans = 1e18;
  for (int i = 3; i <= N-1; ++i) {
    ll P, Q, R, S;
    int lb = 2, ub = i, mid;
    while (ub-lb>1) {
      mid = (ub+lb)/2;
      ll dif = abs(2*sum[mid-1]-sum[i-1]) - abs(2*sum[mid-2]-sum[i-1]);
      if (dif > 0) ub = mid;
      else lb = mid;
    }
    P = sum[lb-1]; Q = sum[i-1]-sum[lb-1];
    lb = i+1; ub = N+1;
    while (ub-lb>1) {
      mid = (ub+lb)/2;
      ll dif = abs(2*sum[mid-1]-sum[N]-sum[i-1]) - abs(2*sum[mid-2]-sum[N]-sum[i-1]);
      if (dif > 0) ub = mid;
      else lb = mid;
    }
    R = sum[lb-1]-sum[i-1]; S = sum[N]-sum[lb-1];
    ans =  min(ans, max(max(P,Q), max(R,S)) - min(min(P,Q),min(R,S)));
  }

  cout << ans << endl;

}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <set>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    int N;
    cin >> N;
    string A, B, C;
    cin >> A >> B >> C;
    int ans = 0;
    for(int i = 0; i < N; i++){
        set<char> chars;
        chars.insert(A[i]);
        chars.insert(B[i]);
        chars.insert(C[i]);
        ans += chars.size() - 1;
    }
    cout << ans << endl;
}


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

int main() {
  int64_t x;
  cin >> x;
  int64_t ans, syou, amari;
  syou = x/11;
  amari = x%11;
  if(amari ==0)ans = syou * 2;
  else if(amari <7)ans = syou *2 +1;
  else ans = syou * 2 +2;
  
  cout << ans << endl;
}

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

string s, t;   //入力文字列
int S, T;      //文字列の長さ

bool match(int k) {
  for ( int i = 0; i < T; i++ ) {
    if ( t[i] != s[i+k] && s[i+k] != '?' ) {
      return false;
    }
  }
  return true;
}

string construct(int k) {
  string ans = s;
  for ( int i = 0; i < T; i++ ) {
    ans[k+i] = t[i];
  }
  for ( int i = 0; i < S; i++ ) {
    if ( ans[i] == '?' ) {
      ans[i] = 'a';
    }
  }
  return ans;
}

int main() {
  cin >> s >> t;
  S = s.length();
  T = t.length();
  
  int a = -1;
  for ( int i = 0; i <= S-T; i++ ) {
    if ( match(i) ) {
      a = i;
    }
  }
  string ANS = construct(a);
  
  if ( a == -1 ) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ANS << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int dp[55][55][55][55];
bool u[55][55][55][55];
int main()
{
	while(1)
	{
		int x,y;
		int ax,ay;
		int bx,by;
		cin >> x >> y; if(x == 0) return 0;
		cin >> ax >> ay; ax--; ay--;
		cin >> bx >> by; bx--; by--;
		int f[55][55];
		for(int i=0;i<y;i++)
		{
			for(int j=0;j<x;j++)
			{
				cin >> f[i][j];
			}
		}
		for(int i=0;i<55;i++) for(int j=0;j<55;j++) for(int k=0;k<55;k++) for(int l=0;l<55;l++) dp[i][j][k][l] = INF,u[i][j][k][l] = 0;
		dp[ay][ax][by][bx] = 0;
		queue<P2>que;
		que.push(mp(mp(ay,ax),mp(by,bx)));
		while(!que.empty())
		{
			P2 p = que.front(); que.pop();
			if(u[p.fi.fi][p.fi.sc][p.sc.fi][p.sc.sc]) continue;
			u[p.fi.fi][p.fi.sc][p.sc.fi][p.sc.sc] = true;
			int dx[4]={0,1,0,-1};
			int dy[4]={1,0,-1,0};
			for(int k=0;k<4;k++)
			{
				int ny = p.fi.fi+dy[k];
				int nx = p.fi.sc+dx[k];
				if(0<=ny && ny<y && 0<=nx && nx<x && f[ny][nx]==0)
				{
				}
				else
				{
					ny = p.fi.fi;
					nx = p.fi.sc;
				}
				int ny2 = p.sc.fi+dy[(k+2)%4];
				int nx2 = p.sc.sc+dx[(k+2)%4];
				if(0<=ny2 && ny2<y && 0<=nx2 && nx2<x && f[ny2][nx2]==0)
				{
				}
				else
				{
					ny2 = p.sc.fi;
					nx2 = p.sc.sc;
				}
				if(dp[ny][nx][ny2][nx2] > dp[p.fi.fi][p.fi.sc][p.sc.fi][p.sc.sc]+1)
				{
					dp[ny][nx][ny2][nx2] = dp[p.fi.fi][p.fi.sc][p.sc.fi][p.sc.sc]+1;
					que.push(mp(mp(ny,nx),mp(ny2,nx2)));
				}
			}
		}
		int res = INF;
		for(int i=0;i<y;i++) for(int j=0;j<x;j++) res = min(res,dp[i][j][i][j]);
		if(res >= 100) puts("NA");
		else printf("%d\n",res);
	}
}

Measured memory_bytes: 46768
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = b-a;
		long d = b-a-1;

		if(c%2==0) {
			System.out.print(c/2);
		} else {
			System.out.println(Math.min(a-1,n-b)+1+(d/2));
		}

	}
}


Measured memory_bytes: 23508
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 10000

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int n;
int chain[10005];
int no[4][10005];

void calc_no (int cnt, int curr, int p, int q, int first_color, int curr_color )
{	
	int s1 = 0, s2 = 0;
	for (; p > 0 && chain[p] == curr_color; p--, s1++ );
	for (; q <= n && chain[q] == curr_color; q++, s2++ );
	int len = s1 + s2 + (cnt == 0 ? 1 : 0 );
	if (len >= 4 ){
		no[first_color][curr] += len;
		if (chain[p] == chain[q] )
			calc_no (cnt+1, curr, p, q, first_color, chain[p] );
	} // end if
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.chain", "r", stdin );
	while (scanf ("%d", &n ), n ){
		memset (chain, -1, sizeof (chain ) );
		chain[0] = 0;
		for (int i = 1; i <= n; i++ ){
			scanf ("%d", &chain[i] );
		} // end rep

		memset (no, 0, sizeof (no ) );
		for (int i = 1; i <= n; i++ ){
			for (int j = 1; j <= 3; j++ ){
				calc_no (0, i, i-1, i+1, j, j );
			} // end rep
		} // end for
		int res = INF;
		for (int i = 1; i <= n; i++ ){
			for (int j = 1; j <= 3; j++ ){
				res = min (res, n-no[j][i] );
			} // end rep
		} // end for
		printf ("%d\n", res );
	} // end while
	
	return 0;
}

Measured memory_bytes: 1392
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  int H,W;
  cin>>H>>W;
  string s="";
  vector<string> a(H);
  for(int i=0;i<W+2;i++)s+='#';
  cout<<s<<"\n";
  for(int i=0;i<H;i++){
    cout<<'#';
    string a;
    cin>>a;
    cout<<a;
    cout<<"#\n";
  }
  cout<<s<<"\n";
  
  
  


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
#define mod (1000000007)
main(){
  int n;
  string v,w;
  map<string,bool> m;
  cin>>n>>w;
  m[w]=true;
  while(--n){
    v=w;
    cin>>w;
    if(*(v.end()-1)!=w[0]||m[w])cout<<"No",exit(0);
    m[w]=true;
  }
  cout<<"Yes";
}

Measured memory_bytes: 256
import java.util.Scanner;
  
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str;
        int sum;
        
        while(true){
            sum=0;
            str = sc.next();
            for(int i=0;i<str.length();i++){
                sum += str.charAt(i)-'0';
            }
            if(sum==0) break;
            System.out.println(sum);
        } 
    }
}

Measured memory_bytes: 26100
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
struct edge{
    int x,y,u;
};
vector<edge> conn;
const int MAX=12,INF=0x3f3f3f3f;
int a,b,d[MAX][MAX],d_est[MAX][MAX],d_est2[MAX][MAX],val[110][110],x_max,y_max;
int update(int x,int y,int z){
    if(x<0||y<0||z<0) return 0;
    for(int i=1;i<=a;i++){
        for(int j=1;j<=b;j++){
            d_est2[i][j]=min(d_est[i][j],z+i*x+j*y);
            if(d[i][j]>d_est2[i][j]) return 0;
        }
    }
    val[x][y]=z;
    for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) d_est[i][j]=d_est2[i][j];
    return 1;
}
int main(){
    scanf(" %d %d",&a,&b);
    for(int i=1;i<=a;i++){
        for(int j=1;j<=b;j++) scanf(" %d",&d[i][j]);
    }
    for(int i=0;i<=100;i++) for(int j=0;j<=100;j++) val[i][j]=-1;
    for(int i=0;i<=a;i++) for(int j=0;j<=b;j++) d_est[i][j]=INF;
    for(int i=a;i>=1;i--){
        for(int j=b;j>=1;j--){
            int x,y,z,chk=0;
            for(x=0;x<=100&&!chk;x++) for(y=0;y<=100&&!chk;y++) {
                z=d[i][j]-x*i-y*j;
                if(update(x,y,z)) chk=1;
            }
            if(!chk){
                printf("Impossible\n");
                return 0;
            }
        }
    }
    printf("Possible\n");
    for(int i=0;i<=100;i++) for(int j=0;j<=100;j++){
        if(val[i][j]>=0) x_max=max(i,x_max),y_max=max(j,y_max);
    }
    for(int i=1;i<=x_max;i++) conn.push_back({i,i+1,-1});
    for(int i=x_max+2;i<=x_max+y_max+1;i++) conn.push_back({i+1,i,-2});
    for(int i=0;i<=100;i++) for(int j=0;j<=100;j++){
        if(val[i][j]>=0) conn.push_back({i+1,x_max+2+j,val[i][j]});
    }
    printf("%d %d\n",x_max+y_max+2,conn.size());
    for(int i=0;i<conn.size();i++){
        if(conn[i].u==-1) printf("%d %d X\n",conn[i].x,conn[i].y);
        else if(conn[i].u==-2) printf("%d %d Y\n",conn[i].x,conn[i].y);
        else printf("%d %d %d\n",conn[i].x,conn[i].y,conn[i].u);
    }
    printf("%d %d\n",1,x_max+2);
}


Measured memory_bytes: 256
S = list(input())
for i in range(int(len(S)/2)):
  S.pop(-1)
  S.pop(-1)
  S_1 = S[:int(len(S)/2)]
  S_2 = S[int(len(S)/2):]
  if S_1 == S_2:
    print(2*len(S_1))
    break

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {

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

  private Scanner sc = new Scanner(System.in);

  int N;
  int M;
  long[] memo;
  boolean[] broken;

  private long dfs(int pos) {
    if (pos > N) {
      return 0L;
    }
    if (broken[pos]) {
      return 0L;
    }
    if (pos == N) {
      return 1L;
    }
    if (memo[pos] != -1) {
      return memo[pos];
    }

    long res = dfs(pos + 1) + dfs(pos + 2);

    return memo[pos] = res % 1000000007L;
  }

  private void run() {
    N = Integer.parseInt(sc.next());
    M = Integer.parseInt(sc.next());
    broken = new boolean[N + 5];
    for (int i = 0; i < M; i++) {
      int tmp = Integer.parseInt(sc.next());
      broken[tmp] = true;
    }

    memo = new long[N + 5];
    for (int i = 0; i < N + 5; i++) {
      memo[i] = -1;
    }

    long ans = dfs(0);
    System.out.println(ans);

  }
}


Measured memory_bytes: 48364
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
A = sorted(A,reverse=True)
if N % 2 == 0: 
    k = N // 2
    ans = sum(A[:k])*2-A[0]
else:
    k = N // 2 + 1
    ans = sum(A[:k])*2-A[0]-A[k-1]
print(ans)

Measured memory_bytes: 29272
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int d, t, s;
  while (scanf("%d %d %d", &d, &t, &s) != EOF)
  {
    printf("%s\n", d / s + (d % s != 0) <= t ? "Yes" : "No");
  }
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,L;
int A[101];
map<int,int> M;
ll dp[110][110][110];
ll mo=1000000007;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,2*N-1) cin>>A[i+1];
	sort(A+1,A+2*N);
	
	dp[N][1][1]=1;
	for(i=N;i>=2;i--) {
		FOR(j,2*N+1) FOR(k,2*N+1) {
			ll cur=dp[i][j][k];
			if(cur==0) continue;
			
			int left=(A[i]!=A[i-1]);
			int right=(A[2*N-i]!=A[2*N-i+1]);
			
			// same
			(dp[i-1][j+left+right][k+left] += cur)%=mo;
			// left
			for(x=0;x<=k+left-2;x++) (dp[i-1][j+left+right-x][k-1+left-x] += cur)%=mo;
			
			// right
			for(x=k+left+1;x<=j+left+right;x++) (dp[i-1][x][k+left+1] += cur)%=mo;
		}
	}
	ll ret=0;
	FOR(j,2*N+1) FOR(k,2*N+1) ret+=dp[1][j][k];
	cout<<ret%mo<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long 
#define pb push_back
#define fo(i,N) for(int i = 0 ; i < N ; i++)
#define foo(i,x,N) for (int i = x; i < N ; i++)
#define fill(a,val) memset(a,val,sizeof(a))
#define fastio()  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define MAX 1234567
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define inf 1e9+1
#define all(a) a.begin(),a.end()

int n,m;
vector <int> adj[100001];
int dp[100001];

int solve(int x)
{
  if ( dp[x] != -1)
    return dp[x];
  
  dp[x] = 0;

  for(int next : adj[x])
  {
    dp[x] = max(dp[x],1+solve(next));
  }

  return dp[x];

}

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

   int a,b;
   fo(i,m)
   {
    cin >> a >> b;
    adj[a].pb(b);
   }
   fill(dp,-1);
   int ans = 0;

   foo(i,1,n+1)
   ans = max(ans,solve(i));

  

   cout << ans << endl;

}



Measured memory_bytes: 7424
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int main()
{
        LL n;
        cin>>n;
        string s;
        LL a=0;
        LL b=0;
        LL c=0;
        LL d=0;
         fr(i,0,n){
           cin>>s;
           if(s=="AC") a++;
           if(s=="WA") b++;
           if(s=="TLE") c++;
           if(s=="RE") d++;
         } 
            cout<<"AC x "<<a<<endl;
            cout<<"WA x "<<b<<endl;
            cout<<"TLE x "<<c<<endl;
            cout<<"RE x "<<d<<endl;
        
    return 0;
}

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

const int maxn=1e5+7,p=1e9+7;
int a[maxn],n,k;
long long fac[maxn],inv[maxn];
long long maxx,minn;

long long poww(int x,int y)
{
	long long ans=1,tmp=x;
	while(y) {
		if(y&1) ans=ans*tmp%p;
		tmp=tmp*tmp%p;
		y>>=1;
	}
	return ans;
}

long long c(int n,int m)
{
	return (fac[n]*inv[m]%p)*inv[n-m]%p;
}

int main()
{
	fac[0]=inv[0]=1;
	for(int i=1;i<maxn;++i) fac[i]=fac[i-1]*i%p;
	inv[maxn-1]=poww(fac[maxn-1],p-2);
	for(int i=maxn-2;i>=1;--i) inv[i]=inv[i+1]*(i+1)%p;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",a+i);
	sort(a+1,a+n+1);
	for(int i=k;i<=n;++i) {
		maxx+=c(i-1,k-1)*a[i]%p;
		maxx%=p;
	}
	for(int i=1;i<=n-k+1;++i) {
		minn+=c(n-i,k-1)*a[i]%p;
		minn%=p;
	}
	printf("%lld",(maxx-minn+p)%p);
}

Measured memory_bytes: 2176
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    //整数の入力
    int N = sc.nextInt();
    
    int x = 0;
    int y = 0;
    
    x = 800 * N;
    y = 200 * (N / 15);
    //x-yの出力
    System.out.println(x - y);
  }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3000;
int n;
double a[3000], dp[3000][3000];
double f(int i, int c){
	if( i == n )
		return c > n/2;
	double &dp = :: dp[i][c];
	if( dp != -1 )
		return dp;
	return dp = a[i]*f(i+1, c+1) + (1-a[i])*f(i+1, c);
}
int main()
{
	
	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];
	for(int i=0; i<=n; ++i)
		for(int j=0; j<=n; ++j)
			dp[i][j] = -1;
	cout << setprecision(9) << fixed << f(0, 0);
}

Measured memory_bytes: 70784
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
# define M_PIl        3.141592653589793238462643383279502884
using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  for(ll i=1;i<=5;i++){
    ll a; cin >> a;
    if(a==0){
      cout << i ;
      return 0;
    }
  }

}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    priority_queue<int> que;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        que.push(A[i]);
    }
    
    for(int i = 0; i < N; ++i){
        int temp = que.top();
        if(temp != A[i]){
            cout << temp << endl;
        }
        else{
            que.pop();
            cout << que.top() << endl;
            que.push(temp);
        }
    }
    
    while(!que.empty()){
        cerr << que.top() << endl;
        que.pop();
    }
}

Measured memory_bytes: 3316
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

dp = [[0 for _ in range(t)] for _ in range(n+1)]

ab.sort()

ans = 0
i = 0
for a, b in ab:
    i += 1
    ans = max(b, ans)
    for j in range(t):
        dp[i][j] = dp[i-1][j]
    for j in range(t):
        if dp[i-1][j] > 0:
            if j + a >= t:
                ans = max(dp[i-1][j] + b, ans)
            else:
                dp[i][j+a] = max(dp[i][j+a], dp[i-1][j] + b)
                ans = max(dp[i][j+a], ans)
    if a < t:
        dp[i][a] = max(dp[i][a], b)
print(ans)


Measured memory_bytes: 123864
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;



int main(){
    double a,b,c,d,e,f;
    vector<double> tmp(2);
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
        double x=(c*e-f*b)/(a*e-d*b);
        double y=(c-a*x)/b;
        if(abs(x)<1e-10){
            x=0;
        }
        if(abs(y)<1e-10){
            y=0;
        }
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 1228
n,a,b,c,d = map(int,input().split())

s=input()

s=list(s)

for i in range(a,max(c,d)):
    if s[i-1] == s[i] == '#':
        print('No')
        exit()

if c < d:
    print('Yes')
else:
    for i in range(b-2,d-1):
        if s[i] == s[i+1] == s[i+2] == '.':
            print('Yes')
            exit()
    print('No')

Measured memory_bytes: 61424
#include <stdio.h>

int main(void){
    char ch;
    int start = 0,sum;
    scanf("%c",&ch);
    while(ch != '0' || start != 0){
        if(ch == '\n'){
            printf("%d\n",sum);
            start = 0;
            sum = 0;
        } else {
            start = 1;
            sum += ch - '0';
        }
        scanf("%c",&ch);
    }
    return 0;
}

Measured memory_bytes: 536