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

using namespace std;

template<typename T>
void Print(const T* pArray, int size)
{
	for (int i = 0; i < size; ++i)
		cout << pArray[i] << (i != size - 1 ? " " : "\n");
}

/**
 * T objects must provide operator< and operator=
 */
template<typename T>
void BubbleSort(T* pArray, int size, int& count)
{
	T temp;
	// 前面是有序数据, j表示无序数据最前一位的索引
	// [0]..[i][j]..[size-1]
	// 0到i是有序数据,j到size-1是无序数据
	for (int i = 0; i < size - 1; ++i)
	{
		// 无序数据两两比较将当前的最值（最小值最大值）
		// 加入到有序数据中
		for (int j = size - 1; j > i; --j)
		{
			if (pArray[j] < pArray[j - 1])
			{
				temp = pArray[j - 1];
				pArray[j - 1] = pArray[j];
				pArray[j] = temp;
				++count;
			}
		}
	}
}

int main()
{
	int n;
	cin >> n;
	int* pArray = new int[n];
	for (int i = 0; i < n; ++i)
		cin >> pArray[i];

	int count = 0;
	BubbleSort(pArray, n, count);
	Print(pArray, n);
	cout << count << endl;
	delete[] pArray;

	return 0;
}


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

int main(){
	long long A, B, C, D;
	std::cin >> A >> B >> C >> D;
	while(1){
		C -= B;
		if(C<=0)
			break;
		A -= D;
		if(A<=0)
			break;
	}
	if(A<=0){
		std::cout << "No" << std::endl;
	}else{
		std::cout << "Yes" << std::endl;
	}
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner Input = new Scanner(System.in);
        String O = Input.next();
        String E = Input.next();

        if (O.length() > E.length()) {
            String Ans = "";
            for (int I = 0; I < O.length(); I++) {
                if (I != O.length() - 1) {
                    Ans += O.charAt(I) + "";
                    Ans += E.charAt(I) + "";
                } else {
                    Ans += O.charAt(I) + "";
                }
            }
            System.out.println(Ans);
        } else {
            String Ans = "";
            for (int I = 0; I < O.length(); I++) {
                Ans += O.charAt(I) + "";
                Ans += E.charAt(I) + "";
            }
            System.out.println(Ans);
        }

    }
}//Keep Copying This Useless Code


Measured memory_bytes: 21972
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  int D,N;cin>>D>>N;
  int E=pow(100,D);
  int ans=N*E;
  if(N==100)ans+=pow(100,D);
  print(ans);
}


Measured memory_bytes: 384
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()

def point(aite):
    if aite == "r":
        return p
    elif aite == "s":
        return r
    else:
        return s

ten = 0
kako = ["o"]*k
for i in range(n):
    if kako[i%k] == t[i]:
        kako[i%k] = "o"
    else:
        kako[i%k] = t[i]
        ten += point(t[i])

print(ten)


Measured memory_bytes: 3828
import java.util.Scanner

import scala.io.StdIn._
object Main extends App {

  def read(): (Int, Array[Int]) = {
    val sc: Scanner = new Scanner(System.in)
    val n = sc.nextInt()
    val arr = Array.fill(n)(sc.nextInt)
    sc.close()
    (n, arr)
  }

  def solve(): Int = {
    val (_, arr) = read()
    val sorted = arr.sorted
    val len = sorted.length
    val maxLen = Math.max(len, sorted(len-1)) + 1
    val cntArr = Array.fill(maxLen)(0)

    sorted.foreach { num =>
      if(cntArr(num) != 0) cntArr(num) = 2
      else (num until maxLen by num).foreach(cntArr(_) += 1)
    }
    sorted.foldLeft(0) { (cnt, num) =>
      if(cntArr(num) == 1) cnt+1 else cnt
    }
  }

  println(solve())

}


Measured memory_bytes: 64716
O = input()
E = input()
Olist = []
Elist = []
S = ''
for i in O:
  Olist.append(i)
for i in E:
  Elist.append(0)
  Elist.append(i)
for i in range(len(Elist)):
  if i % 2 ==0 :
    Elist[i] = Olist[int(i/2)]
for i in range(len(Elist)):
  S = S + Elist[i]
if len(O) > len(E):
  print(S + O[-1])
else:
  print(S)

Measured memory_bytes: 38384
#include<stdio.h>
int main(void){
    int a,b,c;
    int i,l;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0)l++;
    }
    printf("%d\n",l);
    return 0;
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int i,n,t;
    string s;
    cin >> s;
    if(s=="SAT")
    {
        cout << 1 <<endl;
    }
    else if(s=="FRI")
    {
        cout << 2 <<endl;
    }
    else if(s=="THU")
    {
        cout << 3 <<endl;
    }
     else if(s=="WED")
    {
        cout << 4 <<endl;
    }
     else if(s=="TUE")
    {
        cout << 5 <<endl;
    }
    else if(s=="MON")
    {
        cout << 6 <<endl;
    }
    else if(s=="SUN")
    {
        cout << 7 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    int cnt = 0;
    vector<int> a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];
    bool ok = false;
    for (int i=1;i<=n;i++) {
        if(i==1) {
            if(i==a[i]) cnt++;
            ok = true;
        }else {
            if(i==a[i]) {
                cnt++;
                if(ok) cnt--, ok = false;
                else ok = true;
            } else {
                ok = false;
            }
        }
    }
    cout << cnt;
}


Measured memory_bytes: 640
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int X = sc.nextInt();

        if(A+B<=X){
            System.out.println("NO");
        }
        else{
            if(A>X){
                System.out.println("NO");
            }
            else{
                System.out.println("YES");
            }
        }
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;

int N,M,L,K,A,H;
bool re[100];
int cost[100][100];

struct Node{
	int total,rem,pos,total_b;
};

bool operator < (Node a,Node b){
	return a.total>b.total;
}


void solve()
{
	memset(re,false,sizeof(re));
	memset(cost,-1,sizeof(cost));
	re[A]=re[H]=true;
	for(int i=0;i<L;i++){int t;cin>>t;re[t]=true;}

	for(int i=0;i<K;i++){
		int in,out,c;cin>>in>>out>>c;
		cost[in][out]=cost[out][in]=c;
	}

	vector<vector<Node> >V(N);
	Node first;
	first.rem=M; first.total=0; first.pos=A;first.total_b=0;
	priority_queue<Node> Q;
	Q.push(first);
//	cout<<endl<<endl;

	while(!Q.empty()){
		Node now=Q.top();
		Q.pop();
//		cout<<now.pos<<" "<<now.rem<<" "<<now.total<<endl;
		if(now.rem<0) continue;
		if(now.pos==H){cout<<now.total-min(now.total_b,now.rem)<<endl; return;}
		bool ok=true;
		for(int i=0;i<V[now.pos].size();i++){
			if(V[now.pos][i].rem>=now.rem && V[now.pos][i].total<=now.total){
				ok=false;
				break;
			}
		}
		if(!ok) continue;
		V[now.pos].push_back(now);

		for(int i=0;i<N;i++){
			if(cost[now.pos][i]==-1) continue;
			Node next;
			if(re[i]){
				if(now.rem<cost[now.pos][i]) continue;
				next.rem=M;
				next.total=now.total+cost[now.pos][i]+M-now.rem+cost[now.pos][i];
				next.pos=i;
				next.total_b=now.total_b+M-now.rem+cost[now.pos][i];
			}
			else{
				next.rem=now.rem-cost[now.pos][i];
				next.total=now.total+cost[now.pos][i];
				next.pos=i;
				next.total_b=now.total_b;
			}
			Q.push(next);
		}

	}

	cout<<"Help!"<<endl;
}



int main(){
	while(cin>>N>>M>>L>>K>>A>>H){
		if(N==0) break;
		solve();
	}
	return 0;
}

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

using namespace std;
using ll = long long;

//cout << std::fixed << std::setprecision(15) << y << endl;

int main() {
    ll n,k,q = 0;
    cin >> n >> k >> q;
    vector<ll> ans(n,0);
    for(ll i = 0;i < q;i++){
        ll tmp = 0;
        cin >> tmp;
        ans[tmp - 1] ++;
    }
    for(ll i = 0;i < n;i++){
        if(q - ans[i] < k){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
static const int giga = pow(10,9);

int main(void){
  vector<int> a;
  int temp;
  for(int i = 0; i < 3; i++){
    cin >> temp;
    a.push_back(temp);
  }
  sort(a.begin(), a.end(), greater<int>());

  if(a[0] == a[1] + a[2]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
expression = input().split()
stack = []
for i in expression:
    if i in ['+', '-', '*']:
        a = stack.pop()
        b = stack.pop()
    if i == '+':
        stack.append(b + a)
    elif i == '-':
        stack.append(b - a)
    elif i == '*':
        stack.append(b * a)
    else:
        stack.append(int(i))

print(stack[0])



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<char> vec(n);
  int i;
  for(i=0;i<n;i++){
    cin >> vec.at(i);
  }
  for(i=0;i<n;i++){
    if(vec.at(i)=='Y'){
      cout << "Four";
      return 0;
    }
  }
  cout << "Three";
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
char s[N];
int main()
{
	int n,q,k;
	scanf("%d%s%d",&n,s+1,&q);
	while(q--)
	{
		scanf("%d",&k);
		long long ans=0,sd=0,sm=0,sdm=0;
		for(int i=1;i<=n;i++)
		{
			if(s[i]=='D')
				sd++;
			if(s[i]=='M')
				sm++,sdm+=sd;
			if(s[i]=='C')
				ans+=sdm;
			if(i<k)
				continue;
			if(s[i-k+1]=='D')
				sd--,sdm-=sm;
			if(s[i-k+1]=='M')
				sm--;
		}
		printf("%lld\n",ans);
	} 
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	string s;
	cin>>s;
	ll dp[2][s.size()+1];
	REP(i,0,s.size()+1){
		dp[0][i] = 0; dp[1][i] = 0;
	}
	REP(i,1,s.size()+1){
		if(s[i-1] == '?'){
			dp[0][i] = max(dp[0][i-1],dp[1][i-1]);
			dp[1][i] = max(1 + dp[0][i-1] + 1,1 + dp[1][i-1]);	
		}
		else {
			if(s[i-1] == 'P'){
				if(s[i-2] == '?')
					dp[0][i] = max(dp[0][i-1],dp[1][i-1]);
				else if(s[i-2] == 'D')
					dp[0][i] = dp[1][i-1];
				else 
					dp[0][i] = dp[0][i-1];
			}
			else {
				if(s[i-2] == '?')
					dp[1][i] = max(1 + dp[0][i-1] + 1,1 + dp[1][i-1]);
				else if(s[i-2] == 'D')	
					dp[1][i] = 1 + dp[1][i-1];
				else 
					dp[1][i] = 1 + dp[0][i-1] + 1;
			}
		}
	}
	string out = "";
	REPI(i,0,s.size()){
		if(s[i] == '?'){
			if(dp[0][i+1] >= dp[1][i+1]) out.push_back('P');
			else out.push_back('D');
		}
		else out.push_back(s[i]);
	}
	reverse(out.begin(),out.end());
	cout<<out<<endl;
	return 0;
}




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

using namespace std;

int main() {
	long long sum = 0;
	long long x;
	cin >> x;
	long long num = x % 11;
	x -= num;
	sum += x / 11 * 2;
	if (num == 0){}
	else if (num <= 6)sum++;
	else sum += 2;
	cout << sum << endl;
	return 0;
}

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

int64_t calculateMultiply(std::vector<std::pair<int, int>>& v) {
  int n = v.size();
  std::vector<std::vector<int64_t>> m(n, std::vector<int64_t>(n, 0));
  for (int l = 1; l < n; ++l) {
    for (int i = 0; i < n-l; ++i) {
      int j = i+l;
      m[i][j] = INT64_MAX;
      for (int k = i; k < j; ++k) {
        int q = m[i][k] + m[k+1][j] + (v[i].first)*(v[k].second)*(v[j].second);
        if (q < m[i][j]) {
          m[i][j] = q;
        }
      }
    }
  }
  return m[0][n-1];
}


int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int>> v;
  for (int i = 0; i < n; ++i) {
    int a, b;
    std::cin >> a >> b;
    v.push_back({a, b});
   }
  std::cout << calculateMultiply(v) << std::endl;
}

Measured memory_bytes: 3204
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const NIL = -1

var sc = bufio.NewScanner(os.Stdin)

var dummy = &Node{}

type Node struct {
	key    int
	parent *Node
	left   *Node
	right  *Node
}

func (n *Node) children() []*Node {
	var res []*Node
	if n.left != dummy {
		res = append(res, n.left)
	}
	if n.right != dummy {
		res = append(res, n.right)
	}
	return res
}

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	dummy.parent = dummy
	dummy.left = dummy
	dummy.right = dummy
}

func insert(key int) {
	node := &Node{key: key, left: dummy, right: dummy}

	parent := dummy
	leaf := dummy.left
	for leaf != dummy {
		parent = leaf
		if node.key < leaf.key {
			leaf = leaf.left
		} else {
			leaf = leaf.right
		}
	}

	node.parent = parent
	if parent == dummy {
		dummy.left = node
		dummy.right = node
	} else if node.key < parent.key {
		parent.left = node
	} else {
		parent.right = node
	}
}

func preOrder(node *Node, w io.Writer) {
	if node == dummy {
		return
	}

	fmt.Fprint(w, " ", node.key)
	preOrder(node.left, w)
	preOrder(node.right, w)
}

func inOrder(node *Node, w io.Writer) {
	if node == dummy {
		return
	}

	inOrder(node.left, w)
	fmt.Fprint(w, " ", node.key)
	inOrder(node.right, w)
}

func orderPrint(root *Node, w io.Writer) {
	inOrder(root, w)
	fmt.Fprintln(w)
	preOrder(root, w)
	fmt.Fprintln(w)
}

func find(key int) *Node {
	node := dummy.left
	for node != dummy {
		if key == node.key {
			return node
		}
		if key < node.key {
			node = node.left
		} else {
			node = node.right
		}
	}
	return dummy
}

func delete(node *Node) bool {
	if node == dummy {
		return false
	}
	children := node.children()
	switch len(children) {
	case 0:
		parent := node.parent
		if parent.left == node {
			parent.left = dummy
		} else {
			parent.right = dummy
		}
	case 1:
		child := children[0]
		parent := node.parent
		child.parent = parent
		if parent.left == node {
			parent.left = child
		} else {
			parent.right = child
		}
	case 2:
		next := node.right
		for next.left != dummy {
			next = next.left
		}
		node.key = next.key
		delete(next)
	}
	return true
}

func main() {
	n := scanInt()
	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		command := scanString()
		switch command {
		case "insert":
			num := scanInt()
			insert(num)
		case "print":
			root := dummy.left
			orderPrint(root, w)
		case "find":
			num := scanInt()
			if find(num) == dummy {
				fmt.Fprintln(w, "no")
			} else {
				fmt.Fprintln(w, "yes")
			}
		case "delete":
			num := scanInt()
			node := find(num)
			delete(node)
		}
	}
	w.Flush()
}



Measured memory_bytes: 23644
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, x = MAP()
a = LIST()

ans = max(0, a[0]-x)
a[0] = min(a[0], x)

for i in range(1, N):
	ans += max(0, a[i-1]+a[i]-x)
	a[i] = min(a[i], x-a[i-1])
print(ans)


Measured memory_bytes: 16200
S = list(input())
T = list(input())
now = 0
idxS_dict = {}
idxT_dict = {}
for i in range(26):
    idxS_dict[chr(ord('a') + i)] = []
    idxT_dict[chr(ord('a') + i)] = []
for i in range(len(S)):
    idxS_dict[S[i]].append(i)
    idxT_dict[T[i]].append(i)

S_vals = idxS_dict.values()
T_vals = idxT_dict.values()

for val in S_vals:
    if not val in T_vals:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 17192
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int main() {
	int n,z,w;
	cin >> n;
	cin >> z >> w;
	if(n==1){
		int b;
		cin >> b;
		cout << abs(w-b) << endl;
		return 0;
	}
	int _, a, b;
	REP(i, n-2) cin >> _;
	cin >> a >> b;

	cout << (abs(a-b) < abs(w-b) ? abs(w-b) : abs(a-b)) << endl;
	cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<stdio.h>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
struct edge { int to, cost; };
int a[114514];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int sum = 0;
	rep(i, n)sum += a[i];
	sort(a, a + n);
	if (sum & 1) {
		rep(i, n) {
			if (a[i] & 1) {
				sum -= a[i];
				break;
			}
		}
	}
	cout << sum / 2 << endl;
}


Measured memory_bytes: 3116
// https://atcoder.jp/contests/abc049/tasks/abc049_b

#include <iostream>
#include <vector>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int h, w;
  string c;
  vector<string> r;

  cin >> h >> w;

  for (size_t i = 0; i < h; i++)
  {
    cin >> c;
    r.push_back(c);
    r.push_back(c);
  }

  for (auto o : r)
    cout << o << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int soma (int num) {
    int soma = 0;
    while (num != 0) {
        soma += num % 10;
        num /= 10;
    }
    return soma;
}

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

    int A = 1, B = N - 1;
    int menor = soma(A) + soma(B);
    while (A < B) {
        int somaTemp = soma(A) + soma(B);
        if (somaTemp < menor){
            menor = somaTemp;
        }
        A++;
        B--;
    }

    printf("%d\n", menor);
    return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toInt)
    val hs = (1..N).map { readLine()!!.toInt() }.sorted()
    println((0..N-K).map { hs[it+K-1] - hs[it] }.min()!!)
}

Measured memory_bytes: 48336
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;


int main(){
   int a,b,c;
   cin>>a>>b>>c;
   if(a==b)cout<<c<<endl;
   else if(b==c)cout<<a<<endl;
   else cout<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	string s;
	cin >> s;
	int rcont, bcont;
	rcont = 0; bcont = 0;
	for (int i=0; i<N; i++) {
		
		if (s.at(i) == 'R') {
			rcont = rcont + 1;
		}
		else {
			bcont = bcont + 1;
		}
	}
	if (rcont > bcont) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}


Measured memory_bytes: 256
from heapq import *
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
X.sort(reverse=True)
Q=[]
heapify(Q)
Y=0
mod=998244353
for i in range(N):
  Y=1
  while len(Q):
    if Q[0][0]<X[i][0]+X[i][1]:
      Y=Y*Q[0][1]%mod
      heappop(Q)
    else:
      break
  heappush(Q,(X[i][0],Y+1))
P=1
while len(Q):
  P=P*heappop(Q)[1]%mod
print(P)

Measured memory_bytes: 116972
import sys
import time
import heapq

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class PriorityQueue:
    class Reverse:
        def __init__(self, val):
            self.val = val

        def __lt__(self, other):
            return self.val > other.val

        def __repr__(self):
            return repr(self.val)

    def __init__(self, x=None, desc=False):
        if not x:
            x = []
        if desc:
            for i in range(len(x)):
                x[i] = self.Reverse(x[i])
        self._desc = desc
        self._container = x
        heapq.heapify(self._container)

    @property
    def is_empty(self):
        return not self._container

    def pop(self):
        if self._desc:
            return heapq.heappop(self._container).val
        else:
            return heapq.heappop(self._container)

    def push(self, item):
        if self._desc:
            heapq.heappush(self._container, self.Reverse(item))
        else:
            heapq.heappush(self._container, item)

    def top(self):
        if self._desc:
            return self._container[0].val
        else:
            return self._container[0]

    def sum(self):
        return sum(self._container)

    def __len__(self):
        return len(self._container)


def main():
    import bisect
    q = int(input())
    left = PriorityQueue([-INF], desc=True)
    right = PriorityQueue([INF])
    const = 0
    cur_f = 0
    length = 0

    for _ in range(q):
        val = list(map(int, readline().split()))
        if val[0] == 1:
            length += 1
            new_a = val[1]
            const += val[2]
            l = left.top()
            r = right.top()
            cur_x = l
            if length % 2 == 1:
                if new_a < l:
                    right.push(left.top())
                    left.push(new_a)
                    cur_f += abs(l - new_a)
                elif new_a <= r:
                    left.push(new_a)
                    right.push(new_a)
                else:
                    left.push(right.top())
                    right.push(new_a)
                    cur_f += abs(r - new_a)
            else:
                if new_a < l:
                    left.pop()
                    left.push(new_a)
                    cur_f += abs(l - new_a)
                else:
                    right.pop()
                    right.push(new_a)
                    cur_f += abs(r - new_a)
        else:
            print(left.top(), cur_f + const)


if __name__ == '__main__':
    main()


Measured memory_bytes: 94804
import sys
sys.setrecursionlimit(10**5)
N,u,v=map(int,input().split())

du,dv=[0]*-~N,[0]*-~N
T=[list() for i in range(-~N)]

def dfs(p,t,v,d):
  d[v]=t
  for i in T[v]:
    if i!=p:
      dfs(v,t+1,i,d)

for i in range(N-1):
  a,b=map(int,input().split())
  T[a].append(b)
  T[b].append(a)

dfs(0,0,u,du)
dfs(0,0,v,dv)

c=0
for i in range(1,-~N):
  if len(T[i])==1 and i!=v:
    if du[i]<dv[i]:
      c=max(c,~-dv[i])

print(c)



Measured memory_bytes: 103656
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans,ans2;

//�ő����
ll gcd(ll a,ll b){
    
    if(a==0 || b==0)return 0;
    if(a<b){
        ll sw;
        sw=a;
        a=b;
        b=sw;
    }
    
    ll r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
//�ŏ����{��
ll lcm(ll a,ll b){


    if(a==0 || b==0)return 0;

    return a/gcd(a,b)*b;

}

signed main(){

    int n;
    pair<int,int> p[2*111111];
    cin>>n;
    rep(i,n)cin>>p[i].second>>p[i].first;
    sort(p,p+n);
    int time=0;
    rep(i,n){
        time+=p[i].second;
        if(time>p[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
}


Measured memory_bytes: 3712
N,M,C = map(int,input().split())
B = list(map(int,input().split()))

ans = 0

for _ in range(N):
  A = list(map(int,input().split()))
  score = 0

  for i in range(M):
    score += A[i] * B[i]
  score += C

  if score > 0:
    ans += 1

print(ans)

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int N;
	ll D;

	cin >> N >> D;

	V<ll> X(N), Y(N);

	int ans = 0;

	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i];
		ans += (X[i] * X[i] + Y[i] * Y[i] <= D * D);
	}

	cout << ans << '\n';
	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
	return 0;
}


Measured memory_bytes: 6324
#include <bits/stdc++.h>
using namespace std;
void alert(vector<string> vec){
  int64_t N = vec.size();
  for(int64_t i=0; i<N-1; i++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(N-1) << endl;
}

int main(){
  int64_t N; cin >> N;
  vector<string> S(N);
  for(int64_t i=0; i<N; i++){
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  int64_t ans = 1;
  for(int64_t i=1; i<N; i++){
    if(S.at(i)!=S.at(i-1)) ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<double> x(N);
	vector<string> u(N);
	
	for (int i = 0; i < N; i++)
	{
		cin >> x[i];
		cin >> u[i];
	}
	
	double answer = 0.0;
	for (int i = 0; i < N; i++)
	{
		if (u[i] == "JPY")
		{
			answer += x[i];
		}
		else if (u[i] == "BTC")
		{
			// 1BTC あたり 380000.0円
			double BTC = 380000.0 * x[i];
			answer += BTC;
		}
	}
	
	// 出力
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 300100
#define MOD 998244353
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 10000000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

signed main()
{
  int n;
  int k;
  cin>>n>>k;
  int a;
  int A[n+k]={0};
  for (int i=0;i<n;i++)
  {
  	cin>>a;
  	A[i]=a;
  }
int dis[n+1]={0};
if (n==1)
{
	cout<<0;
	return 0;
}
else
{

dis[0]=INF;
dis[1]=0;
dis[2]=abs(A[1]-A[0]);

	for (int j=3;j<=k;j++)
	{
		int di =0;
	
		di=min(dis[1]+abs(A[0]-A[j-1]),dis[2]+abs(A[1]-A[j-1]));
		
		for (int i=3;i<=j-1;i++)
		{
			di=min(di,dis[i]+abs(A[i-1]-A[j-1]));
		}
		dis[j]=di;
	}

	for (int i=k+1;i<=n;i++)
	{ int dis1=0;
		if(k>=2)
		dis1=min(dis[i-1]+abs(A[i-2]-A[i-1]),dis[i-2]+abs(A[i-3]-A[i-1]));
	else
		dis1=dis[i-1]+abs(A[i-2]-A[i-1]);

		for (int j=i-3;j>=i-k;j--)
		{
			dis1=min(dis1,dis[j]+abs(A[j-1]-A[i-1]));
		} 
		dis[i]=dis1;
	}
	
	cout<<dis[n]<<endl;
}
return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    a = LI()
    a4, a2, a1 = [0 for _ in range(3)]
    for i in a:
        if i%4 == 0:
            a4 += 1
        elif i%2 == 0:
            a2 += 1
        else:
            a1 += 1
    if a1 == 0:
        print("Yes")
    else:
        if a4 == 0:
            print("No")
        elif a2 == 0:
            print("Yes" if a4 >= a1 -1 else "No")
        else:
            print("Yes" if a4 >= a1 else "No")
main()

Measured memory_bytes: 94096
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

string N;
int main(){
    cin>>N;
    for(ll i=0;i<3;i++){
        if(N[i]=='7'){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    pair<int,int> p[n];
    int ans=-1;
    pair<int,int> mx;
    int l=1,r=INF;
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        p[i]={l,r};
        if(ans<r-l+1){
            mx={l,r};
            ans=r-l+1;
        }
    }
    for(int i=0;i<n;i++){
        if(mx!=p[i]){
            l=max(l,p[i].first);
            r=min(r,p[i].second);
        }
    }
    ans+=max(0,r-l+1);
    sort(p,p+n);
    int ansl[n-1],ansr[n-1];
    l=1,r=INF;
    for(int i=0;i<n-1;i++){
        l=max(l,p[i].first);
        r=min(r,p[i].second);
        ansl[i]=r-l+1;
    }
    l=1,r=INF;
    for(int i=n-1;i>0;i--){
        l=max(l,p[i].first);
        r=min(r,p[i].second);
        ansr[i-1]=r-l+1;
    }
    for(int i=0;i<n-1;i++){
        ans=max(ans,max(0,ansl[i])+max(0,ansr[i]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d",&a)
#define STR(a) scanf("%s",a)
#define DBL(a) scanf("%lf",&a)
#define LNG(a) scanf("%lld",&a)
#define PI acos(-1)
#define ff first
#define ss second
int b[100005], c[100005];
int main(){
	int n, m;
	cin>>n>>m;
	vector< int > num;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		num.push_back(a);
	}

	sort(num.begin(), num.end());

	vector< pair< int, int > > query;
	for(int i=1;i<=m;i++){
		cin>>b[i]>>c[i];
		query.push_back({c[i], b[i]});
	}

	sort(query.rbegin(), query.rend());


	long long sum=0, j=0;
	for(int i=0;i<query.size();i++){
		long long val = query[i].ff;

		int pos = lower_bound(num.begin(), num.end(), val)-num.begin();

		if(pos>=j){
			int tmp =pos-j;
			tmp = min(tmp, query[i].ss);
			sum+=tmp*val;
			j+=tmp;
		}
	}

	sum=accumulate(num.begin()+j, num.end(), sum);

	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2296
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author __shangu__
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DIntegerCards solver = new DIntegerCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class DIntegerCards {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            TreeMap<Integer, Integer> map = new TreeMap<>(Collections.reverseOrder());
            for (int i = 0; i < n; ++i) {
                map.merge(in.nextInt(), 1, (k, v) -> k + 1);
            }
            for (int i = 0; i < m; ++i) {
                int cnt = in.nextInt();
                map.merge(in.nextInt(), cnt, (k, v) -> k + cnt);
            }
            long sum = 0;
            for (Integer val : map.keySet()) {
                if (n == 0) break;
                sum += (long) val * Math.min(map.get(val), n);
                n -= Math.min(map.get(val), n);
            }
            out.println(sum);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int a,b;
  cin>>a>>b;
  int n1=ceil(((a*100.0)/8.0));
  int n2=ceil(((b*100.0)/10.0));
  if(floor(n1*0.08)==a && floor(n1*0.1)==b)
    cout<<n1<<endl;
  else if(floor(n2*0.08)==a && floor(n2*0.1)==b)
    cout<<n2<<endl;
  else
    cout<<-1<<endl;
    return 0;
}






Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,a,b,f[5005];
long long dp[5005];
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        f[x]=i;
    }
    for(int i=1;i<=n;i++)
    {
        int pos=f[i];
        long long t=1e18;
        for(int j=1;j<=n;j++)
        {
            t=min(t,dp[j]);
            if(pos==j) dp[j]=t;
            else if(pos>j) dp[j]=t+b;
            else dp[j]=t+a;
        }
    }
    long long ans=1e18;
    for(int i=1;i<=n;i++)
        ans=min(ans,dp[i]);
    printf("%lld\n",ans);
}
/*dp[i][j]表示将第i个数搬移到前j个位置的最小价值*/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	ll n; cin >> n; ll a[n];
	Rep(i, n){
		cin >> a[i];
	}
	sort(a, a + n);
	ll k = a[n - 1], m = inf, b = 0;
	Rep(i, n - 1){
		if(abs(k - a[i] * 2) < m){
			m = abs(k - a[i] * 2);
			b = i;
		}
	}
	cout << a[n - 1] << " " << a[b] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
string s[10],srev[10];
string H[5],W[5];
bool eq[10];
 
bool valid(int idx){
    for(int i = 0 ; i < 5 ; i++){
	if(W[idx][i] == H[i][idx]){
	    return false;
	}
    }
    return true;
}
 
int solve(int idx,int S){
    if(S == (1<<10)-1){
	return 1;
    }
    int res = 0;
    for(int i = 0 ; i < 10 ; i++){
	if((S >> i) & 1) continue;
	if(idx < 5){
	    H[idx] = s[i];
	    res += solve(idx+1,S|(1<<i));
	    if(!eq[i]){
		H[idx] = srev[i];
		res += solve(idx+1,S|(1<<i));
	    }
	}else{
	    W[idx-5] = s[i];
	    if(valid(idx-5)){
		res += solve(idx+1,S|(1<<i));
	    }
	    if(!eq[i]){
		W[idx-5] = srev[i];
		if(valid(idx-5)){
		    res += solve(idx+1,S|(1<<i));
		}
	    }
	}
    }
    return res;
}
 
int main(){ 
    while(cin >> s[0], s[0] != "END"){
	memset(eq,false,sizeof(eq));
	string tmp = s[0];
	reverse(tmp.begin(),tmp.end());
	srev[0] = tmp;
	eq[0] = s[0] == srev[0];
	for(int i = 0 ; i < 9 ; i++){
	    cin >> s[i+1];
	    tmp = s[i+1];
	    reverse(tmp.begin(),tmp.end());
	    srev[i+1] = tmp;
	    eq[i+1] = s[i+1] == srev[i+1];
	}
	cout << solve(0,0)/8 << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

     ll m , n;
     cin>>m>>n;
     ll a[n];
     ll s = 0;
     for(int i=0; i<n; i++) {
        cin>>a[i];
        s += a[i];
     }
     cout<<(s >= m ? "Yes" : "No");
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int x;
  cin >> x;
  int c500, c5;
  c500 = x / 500;
  c5 = (x % 500) / 5;
  cout << c500 * 1000 + c5 * 5 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

using namespace std;

typedef pair<int, int> P;

int n, m, p, q, r;
vector<P> data[2][3];

void calc(int t, int a, int b){
  int pos = 2, cnt = 0, nex = 1 - t, id = 0;
  int c[2] = {a, b};
  
  for(int i=0;i<3;i++) data[nex][i].clear();
  for(int i=0;i<3;i++){
    for(int j=0;j<data[t][i].size();j++){
      if(id == 2) data[nex][pos].push_back(data[t][i][j]);
      else{
        int val = cnt + data[t][i][j].second - data[t][i][j].first + 1;
        if(id == 0 && c[0] < val && c[1] < val){
          data[nex][pos].push_back(P(data[t][i][j].first, data[t][i][j].second - (val - c[id])));
          pos--;
          id++;
          data[nex][pos].push_back(P(data[t][i][j].second - (val - c[id-1]) + 1, data[t][i][j].second - (val - c[id])));
          pos--;
          id++;
          data[nex][pos].push_back(P(data[t][i][j].second - (val - c[id-1]) + 1, data[t][i][j].second));
        }else if(val < c[id]){
          data[nex][pos].push_back(data[t][i][j]);
        }else if(val == c[id]){
          data[nex][pos].push_back(data[t][i][j]);
          pos--;
          id++;
        }else if(val > c[id]){
          int tmp = val - c[id];
          data[nex][pos].push_back(P(data[t][i][j].first, data[t][i][j].second - tmp));
          pos--;
          id++;
          data[nex][pos].push_back(P(data[t][i][j].second - tmp + 1, data[t][i][j].second));
        }
      }
      cnt += data[t][i][j].second - data[t][i][j].first + 1;
    }
  }
}

main(){
  while(cin >> n && n){
    for(int i=0;i<2;i++) for(int j=0;j<3;j++) data[i][j].clear();
    cin >> m >> p >> q >> r;
    data[0][0].push_back(P(1, n));
    for(int i=0;i<m;i++){
      int a, b;
      cin >> a >> b;
      calc(i%2, a, b);
    }
    /*for(int i=0;i<3;i++){
      for(int j=0;j<data[m%2][i].size();j++){
      cout << "(" << data[m%2][i][j].first << "-" << data[m%2][i][j].second << "), ";
      }
      cout << endl;
      }*/
    int ans = 0;
    int cnt = 0;
    for(int i=0;i<3;i++){
      for(int j=0;j<data[m%2][i].size();j++){
        P tmp = data[m%2][i][j];
        int len = tmp.second - tmp.first + 1;
        if(cnt <= p && q <= cnt + len){
          int v1 = tmp.first + (p - cnt - 1);
          int v2 = r - (v1 - 1);
          ans += max(0, min(v2, q - p + 1));
        }else if(p <= cnt && cnt + len <= q){
          int v1 = tmp.first - 1;
          int v2 = r - v1;
          ans += max(0, min(v2, len));
        }else if(cnt <= p && p <= cnt + len){
          int v1 = tmp.first + (p - cnt - 1); 
          int v2 = r - (v1 - 1);
          ans += max(0, min(v2, len - (p - cnt - 1)));
        }else if(cnt <= q && q <= cnt + len){
          int v1 = tmp.first - 1;
          int v2 = r - v1;
          ans += max(0, min(v2, q - cnt));
        }
        cnt += len;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1532
c[99999],n;main(i,j){for(i=2;i*i<=5e4;i++)for(j=i;!c[i]&&j<=5e4;c[j+=i]=1);for(;scanf("%d",&j),*c=j;n=!printf("%d\n",n))for(i=2;i<=j/2;i++)n+=!(c[i]+c[j-i]);}

Measured memory_bytes: 604
import math

A, B, H, M = map(int, input().split())

KA = H / 12 * 360 + ((M / 60) * (360 / 12))
KB = M / 60 * 360

K = abs(KA - KB)
if K > 180:
    K = 360 - K
# if K == 180:
#     print(A + B)
#     exit()
# if K == 0:
#     print(abs(B - A))
#     exit()
cosB = round(math.cos(math.radians(K)), 13)
cc = A ** 2 + B ** 2 - (2 * B * A * cosB)
print(math.sqrt(cc))


Measured memory_bytes: 9508
s,t = gets.chomp.split(' ').map(&:to_s)
a,b = gets.chomp.split(' ').map(&:to_i)
u = gets.chomp.to_s

ans = []

if u == s
	ans = (a - 1),b
else
	ans =  a,(b - 1)
end

print ans.join(' ')

Measured memory_bytes: 1788
#include <stdio.h>
#include <iostream>

using namespace std;

int wa(int x)
{
    if (x == 1)
        return 1;
    else
        return wa(x - 1) + x;
}

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

    int t;
    t = wa(a);

    printf("%d\n", t);
}

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

typedef long long ll;
typedef long double ld;

int N, HALF;
ld prob[3002], dp[3002][3002];

ld calc(int lvl, int tails) {
    if(dp[lvl][tails]) return dp[lvl][tails];
    if(lvl == N) return 1;

    if(tails >= HALF)
        return dp[lvl][tails] = prob[lvl]*calc(lvl + 1, tails);

    return dp[lvl][tails] = prob[lvl]*calc(lvl + 1, tails) + (1 - prob[lvl])*calc(lvl + 1, tails + 1);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    HALF = N/2;

    for(int i = 0; i < N; i++) 
        cin >> prob[i];

    cout << setprecision(10) << calc(0, 0) << "\n";

    return 0;
}


Measured memory_bytes: 138752
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.split_whitespace();
    let mut nums = Vec::new();
    for edge in s {
        nums.push(edge.parse::<u32>().unwrap());
    }
    println!("{}", &nums[0] * &nums[1] / 2);
}

Measured memory_bytes: 4352