akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#define N 10
using namespace std;

int main(){
	string str, ans = "";
	bool h[N][N]; // setinel
	bool v[N][N];
	char dir = 'R';
	int mx = 1;
	int my = 1;
	int i, j, len;
	
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			h[i][j] = v[i][j] = false;
		}
	}

	i = j = 1;
	while(cin >> str){
		if(i == 1) len = str.size();
		if(str.size() == len){
			for (int k = 0; k < str.size(); k++) {
				h[i][k+1] = str[k] == '1' ? true : false;
			}
			i++;
		}else{
			for (int k = 0; k < str.size(); k++) {
				v[j][k+1] = str[k] == '1' ? true : false;
			}
			j++;
		}
	}

	do{
		if (dir == 'L') {
			if(v[my][mx]){
				my++;
				dir = 'D';
			}else if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else{
				mx++;
				dir = 'R';
			}
		}else if (dir == 'R') {
			if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else if(h[my][mx]){
				mx++;
				dir = 'R';
			}else if(v[my][mx]){
				my++;
				dir = 'D';
			}else{
				mx--;
				dir = 'L';
			}
		}else if (dir == 'U') {
			if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else if(h[my][mx]){
				mx++;
				dir = 'R';
			}else{
				my++;
				dir = 'D';
			}
		}else if (dir == 'D') {
			if(h[my][mx]){
				mx++;
				dir = 'R';
			}else if(v[my][mx]){
				my++;
				dir = 'D';
			}else if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else{
				my--;
				dir = 'U';
			}
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 0
#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>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int from,to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
edge G[2010];
int d[2010];
bool negative[2010];

int Bellman_Ford(int s){
	for(int i=0;i<N;i++){
		d[i]=INF;
	}
	d[s]=0;
	for(int i=0;i<N;i++){
		bool update=false;
		for(int i=0;i<M;i++){
			edge e=G[i];
			if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update){
			break;
		}
	}
}

void FN(){
	fill(d,d+N,0);
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			edge e=G[j];
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				if(i==N-1){
					negative[e.to]=true;
				}
			}
		}
	}
}

signed main(){
	cin>>N>>M;
	REP(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		G[i].from=a-1;
		G[i].to=b-1;
		G[i].cost=-c;
	}
	FN();
	DEB(negative[0])END
	if(negative[N-1]==true){
		cout<<"inf"<<endl;
	}
	else{
		Bellman_Ford(0);
		cout<<-d[N-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
ll modpow(ll a, ll n, ll m) {
    ll ret = 1;
    ll now = a;
    while (n > 0) {
        if (n % 2 == 1) ret = ret * now % m;
        now = now * now % m;
        n /= 2;
    }
    return ret;
}
int main() {
    string s;
    cin >> s;
    reverse(all(s));
    int n = sz(s);
    vector<ll> cnt(2019);
    cnt[0] = 1;
    int now = 0;
    rep(i, n) {
        (now += (s[i] - '0') * modpow(10, i + 1, 2019)) %= 2019;
        cnt[now]++;
    }
    ll ans = 0;
    rep(i, 2019) {
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 X, Y;
  std::cin >> X >> Y;
  std::cout << (std::abs(X - Y) <= 1 ? "Brown" : "Alice") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define mod 1000000007
/****************************/
string s;
int main()
{
	int a=0,b=0;
	cin>>s;
	rep(i,SZ(s))
	{
		if(s[i]=='A') a++;
		else b++;
	}
	if(a&&b)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    bool ans; 
    if(s[0] == s[s.size()-1] && t[0] == t[t.size()-1]){
        ans = (s.size()<t.size());
    }
    else{
        ans = s[0] < t[0];
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
  
}

Measured memory_bytes: 256
n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))

count1 = 0
count2 = 0
for i in range(n):
    for j in range(n):
        if j > i and a[i] > a[j]:
            count1 += 1
        if a[i] > a[j]:
            count2 += 1

total = count1 * k + count2 * k * (k - 1) // 2
print(total % (10 ** 9 + 7))


Measured memory_bytes: 3188
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split.to!(int[]);
	
	writeln( max(data[0] * 2 - 1, data[0] + data[1], data[1] * 2 - 1) );
}



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

typedef long long ll;




vector<tuple<ll,ll,ll>> table[20];
//get<0> := x
//get<1> := y
//get<2> := value

ll tmp;

ll i,j;
ll n,m;
ll l,r,f,b,d,u;

void rotate_l(){
	tmp = u;
	u = r;
	r = d;
	d = l;
	l = tmp;
	return;
}

void rotate_r(){
	tmp = u;
	u = l;
	l = d;
	d = r;
	r = tmp;
	return;
}

void rotate_b(){
	tmp = u;
	u = f;
	f = d;
	d = b;
	b = tmp;
	return;
}

void rotate_f(){
	tmp = u;
	u = b;
	b = d;
	d = f;
	f = tmp;
	return;
}

bool solve(){
	cin >> n;
	if(n == 0)return false;

	ll x,y;
	string s;
	for(i=0;i<n;i++){
		cin >> x >> y;
		cin >> l >> r >> f >> b >> d >> u;
		cin >> s;
		m = s.size();
		table[i].clear();
		table[i].emplace_back(x,y,d);
		// cout << x << " " << y << " " << d << endl;
		for(j=0;j<m;j++){
			if(s[j] == 'L'){
				rotate_l();
				x--;
			}else if(s[j] == 'R'){
				rotate_r();
				x++;
			}else if(s[j] == 'B'){
				rotate_b();
				y++;
			}else{
				rotate_f();
				y--;
			}

			bool visited = false;
			auto itr = table[i].begin();
			for(itr = table[i].begin(); itr != table[i].end(); ++itr) {
				int sx, sy, sd;
				tie(sx, sy, sd) = *itr;
				if (sx == x && sy == y) {
					visited = true;
					break;
				}
			}
			if (visited) table[i].erase(itr);
			table[i].emplace_back(x,y,d);
			// cout << x << " " << y << " " << d << endl;
		}
	}

	int N = n;
	vector<int> dp(1 << N, 0);
	for(int b = 0; b < (1 << N); ++b) {
		for(int i = 0; i < N; ++i) {
			if ((b >> i) & 1) continue;

			int score = dp[b];
			for(auto t : table[i]) {
				int x, y, d;
				tie(x, y, d) = t;

				bool filled = false;
				for(int j = 0; j < N; ++j) {
					if(!((b >> j) & 1)) continue;
					for(auto s : table[j]) {
						int sx, sy, sd;
						tie(sx, sy, sd) = s;
						if (sx == x && sy == y) {
							filled = true;
						}
					}
				}

				if (!filled) score += d;
			}

			dp[b | (1 << i)] = max(dp[b | (1 << i)], score);
		}
	}

	cout << dp.back() << endl;
	return true;
}


int main(){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 28;
const long long MOD = 1000000000 + 7;

int main()
{
	int r,g,n,b;
	cin >> r >> g>>b>>n;


	int ans=0;
	for(int a=0;a<=n/r;a++){
		for(int a2=0;a2<=n/g;a2++){
			if(a*r + g*a2 <=n and (n-a*r-g*a2)%b==0){
				ans++;
				//cout<< a <<" "<<a2<<" "<<n-a-a2<<endl;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	R := nextInt()

	fmt.Println(3 * R * R)
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}


Measured memory_bytes: 640
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		h: usize,
		w: usize,
		cs: [Chars; h],
	}

	for y in 0..h {
		for x in 0..w {
			if cs[y][x] == '#' {
				// 上
				if y > 0 && cs[y-1][x] == '#' {continue};
				// 下
				if y < h-1 && cs[y+1][x] == '#' {continue};
				// 左
				if x > 0 && cs[y][x-1] == '#' {continue};
				// 右
				if x < w-1 && cs[y][x+1] == '#' {continue};
				println!("No");
				return;
			}
		}
	}
	println!("Yes");
}



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

const int N = 3005;

bool udah[N][N];
double dp[N][N];
double p[N];
int n;

void read() {
  cin >> n;
  for (int i = 0 ; i < n ; i++) {
    cin >> p[i];
  }
}

double solve(int head, int tail) {
  if (head+tail == n) {
    return head > tail;
  }

  if (udah[head][tail]) return dp[head][tail];
  udah[head][tail] = 1;

  int cur = head + tail;
  dp[head][tail] = (p[cur] * solve(head+1, tail) + (1-p[cur]) * solve(head, tail+1));

  return dp[head][tail];
}

int main() {
  read();
  printf("%.13lf\n", solve(0, 0));
  return 0;
}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;   
const int inf = (int) 1e9+7;
const long long INF = -1000000000000;
int main(){
	fastIO;
	int n,m;
	long long p;
	cin>>n>>m>>p;
	vector< vector< pair<int,long long> > > v1(n);
	vector< vector<int> > v2(n);
	for(int i=0;i<m;i++){
		int a,b;
		long long c;
		cin>>a>>b>>c;
		--a;--b;c-=p;
		v1[a].push_back(make_pair(b,c));
		v2[b].push_back(a); 	
	}        
	queue<int> q;
	bool alg[n];
	for(int i=0;i<n;i++)alg[i]=false;                 
	q.push(n-1);
	alg[n-1]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<(int)v2[x].size();i++){
			int nxt=v2[x][i];
			//cout<<nxt<<" "<<x<<'\n';
			if(alg[nxt] == 0){
				alg[nxt]=1;
				//cout<<nxt<<'\n';
				q.push(nxt);
			}
		}
	}
	
	long long d[n];
	for(int i=0;i<n;i++)d[i]=-1000000000000;
	d[0]=0ll;              
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(d[j] != -1000000000000){
				for(int k=0;k<(int)v1[j].size();k++){
					int nxt = v1[j][k].first;
					if(d[j] + v1[j][k].second > d[nxt]){
		      	d[nxt] = d[j] + v1[j][k].second;
					}               
				}                 			
			}		
		}
	}

	/*for(int i=0;i<n;i++){
		cout<<d[i]<<" ";
	}
	cout<<'\n';*/
	for(int i=0;i<n;i++){
		for(int j=0;j<(int)v1[i].size();j++){
			int nxt=v1[i][j].first;	
			if(d[i] == -1000000000000 || d[nxt] == -1000000000000)continue;
			if(d[i] + v1[i][j].second > d[nxt] && alg[nxt]){
				//cout<<nxt<<" "<<d[nxt]<<" "<<alg[nxt]<<'\n';
				cout<<-1<<'\n';
				return 0;
			}
		}
	}	
	cout<<max(0ll,d[n-1])<<'\n';
	return 0;
}

Measured memory_bytes: 640
N=int(input())
B=list(map(int,input().split()))
lst=[]
while B:
    for i in range(len(B)-1,-2,-1):
        if i==-1:
            print(-1)
            exit()
        elif B[i]==i+1:
            B.pop(i)
            lst.append(i+1)
            break

lst.reverse()
for i in lst:
    print(i)


Measured memory_bytes: 3060
package main

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

func main() {
	a, b, n := readFloat64(), readFloat64(), readFloat64()

	x := math.Min(b-1, n)
	ans := math.Floor(a*x/b) - a*math.Floor(x/b)

	fmt.Println(int(ans))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1756
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	S := nextString()
	b := []byte(S)
	m := map[byte]int{}
	for _, bb := range b {
		m[bb]++
	}
	ans := "Yes"
	if len(m) == 2 {
		for _, v := range m {
			if v != 2 {
				ans = "No"
			}
		}
	} else {
		ans = "No"
	}
	fmt.Println(ans)
}

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

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long q = sc.nextInt();
        long h = sc.nextInt();
        long s = sc.nextInt();
        long d = sc.nextInt();
        int n = sc.nextInt();
        long[] array = {
                8 * q,
                4 * h,
                2 * s};
        Arrays.sort(array);
        if (array[0] <= d) {
            System.out.println(array[0] / 2 * n);
        } else {
            if (n % 2 == 0) {
                n /= 2;
                System.out.println(d * n);
            } else {
                n /= 2;
                System.out.println(d * n + array[0] / 2);
            }
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int extgcd(int a, int b, int& x, int& y){
  int d = a;
  if(b != 0){
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }else{
    x = 1; y = 0;
  }
  return d;
}
int gcd(int a, int b){
  return (b != 0) ? gcd(b, a%b) : a;
}
int main(){
  int a, b, d;
  while(cin>>a>>b>>d && a){
    int g = gcd(a, b);
    assert(d % g == 0);
    a /= g; b /= g; d /= g;
    int x, y;
    extgcd(a, b, x, y);
    x *= d; y *= d;
    int ax = abs(x), ay = abs(y);
    for(int t = -50000; t <= 50000; t++){
      int nx = abs(x + b * t), ny = abs(y - a * t);
      if(ax + ay > nx + ny || (ax + ay == nx + ny && a*ax + b*ay > a*nx + b*ny)){
        ax = nx, ay = ny;
      }
    }
    printf("%d %d\n", ax , ay);
  }
    

  return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;
 
void solve(){
  int n; cin >>n;
  ll a[n],b[n],sum=0;
  for(int i=0; i<n; i++){cin >>a[i]; sum+=a[i];}
  if(n==3) for(int i=1; i<4; i++) cout <<sum-2*a[i%3]<<' ';
  else{
    ll t=0;
    for(int i=1; i<n; i+=2) t+=a[i];
    for(int i=0; i<n; i++){
      b[(2*i)%n]=t;
      t+=a[(2*i)%n]-a[(2*i+1)%n];
    }
    for(int i=0; i<n; i++) cout <<sum-2*b[i]<<' ';
  }
}

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

Measured memory_bytes: 5136
#include<bits/stdc++.h>
#define inf ((int)0x3f3f3f3f)
#define neinf ((int)0xc1c1c1c1)
#define llinf ((ll)0x3f3f3f3f3f3f3f3f)
#define nellinf ((ll)0xc1c1c1c1c1c1c1c1)
#define ull unsigned long long
#define lson root<<1
#define rson root<<1|1
#define uint usigned int
#define Mid int mid=(l+r)>>1;
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
#define Mem(a,b) memset(a,b,sizeof(a))
#define Memv(a,b) for(int i=0;i<=b;i++) a[i].clear()
#define ll long long
#define eps 1e-6
#define PB push_back
#define PI acos(-1)
#define lmove(n) (1<<(n))
#define FI first
#define SE second
#define Ceil(x,y) ((x+y-1)/y)
#define EULER_C 0.57721566490153286060651209
using namespace std;
const int MAXN=1e5+10;
const ll mod=1e9+7;
unordered_map<int,int>f;
int n;
vector<int>a;
bool cmp(int a,int b){
    return a>b;
}
char s1[MAXN];
char s2[MAXN];
int main() {
#ifdef ONLINE_JUDGE
#else
    //freopen("/home/jason/data/out.txt","r",stdin);
    //FREI;
    //FREO;
#endif // ONINLE_JUDGE
    int n;
    scanf("%d",&n);
    scanf("%s",s1);
    scanf("%s",s2);
    ll ans=1;
    int pre=-1;
    for(int i=0;i<n;i++){
        if(s1[i]==s2[i]){
            if(!pre) ans=ans*2%mod;
            else if(pre==-1) ans=3%mod;
            pre=0;
        }
        else{
            i++;
            if(pre&&pre!=-1) ans=ans*3%mod;
            else if(!pre) ans=ans*2%mod;
            else if(pre==-1) ans=6;
            pre=1;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
use std::collections::BinaryHeap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<usize>();
    let (_, m) = (input[0], input[1]);
    let mut bh = BinaryHeap::new();

    let ax = read_vec::<usize>();
    for a in ax {
        bh.push(a);
    }

    for _ in 0..m {
        if let Some(x) = bh.pop() {
            bh.push(x>>1);
        }
    }

    let ans: usize = bh.into_iter().sum();

    println!("{}", ans);
}

Measured memory_bytes: 9464
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
 
void solve() {
    int n;
    cin >> n;
 
    vector<pair<int, int>> p[n + 1];
 
    for (int i = 1; i <= n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int a, b;
            cin >> a >> b;
 
            p[i].push_back({a, b});
        }
    }
 
    int64_t ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) 
    {// loop to all the combinations
        //1 means honest
        bool fl = true;
        for (int i = 1; i <= n; i++) 
        {
            bool isHonest = bit & (1 << (i - 1));// chekc hwo many are honest based on the set bits. check fi its contraddcting one value ans is 0.
            /// take all teh combinations of the honest persons babe
            if (isHonest) 
            {
                for (auto x: p[i]) 
                {
                    int id = x.first - 1;
                    bool hon = bit & (1 << id);
                    if (hon != x.second)/// if onnly one one then anwer willbe true baby
                    fl = false;
                }
            }
        }
        if (fl)ans = max(ans, (int64_t) __builtin_popcount(bit));
    }
    cout << ans << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t = 1;
//    cin >> t;
 
    while (t--)
        solve();
    return 0;
}

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

int main(void)
{
    int n;
    cin >> n;
    int maxv      = 0;
    int dec_count = 0;
    int inc_count = 0;
    vector<ll> h(n);
    rep(i, n) { cin >> h.at(i); }
    int flag = 0;
    rep(i, n - 1)
    {
        if (h.at(i) < h.at(i + 1))
            dec_count = 0;
        else
            dec_count++;
        if (maxv < dec_count) maxv = dec_count;
    }
    cout << maxv << endl;
}


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

using namespace std;

void hawawa()
{
	int a[3];
	for (auto&& i : a) {
		cin >> i;
	}
	sort(a, a + 3);
	cout << a[2] - a[0] << "\n";
}

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


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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

ll mod_pow(ll n, ll m, ll p){
  if(m == 1) return n;
  ll a = mod_pow(n, m/2, p);
  if(m%2 == 0){
  	return ((a*a)%p);
  }else{
    return ((((a*a)%p)*n)%p);
  }
}

ll permutation(ll n, ll k){
  if(k == 0) return 1;
  ll per = n;
  for(int i=1;i<k;i++){
    per = (per*(n-i))%1000000007;
  }
  return per;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  
  if(n-a < a){
    a = n-a;
  }
  if(n-b < b){
    b = n-b;
  }
  ll ca = (permutation(n, a)*mod_pow(permutation(a, a), 1000000005, 1000000007))%1000000007;
  ll cb = (permutation(n, b)*mod_pow(permutation(b, b), 1000000005, 1000000007))%1000000007;
  ll ans = (((mod_pow(2, n, 1000000007)-ca-cb-1)%1000000007)+1000000007)%1000000007;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
vector<pair<int,int> >g[1100];
char in[20];
long long ijk[1100][110];
int v[1100][110];
long long ABS(long long a){return max(a,-a);}
int main(){
	int a,b,c,d,e;
	while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&e),a){
		c--;d--;e--;
		for(int i=0;i<a;i++)g[i].clear();
		for(int i=0;i<b;i++){
			int p,q;scanf("%d%d",&p,&q);
			p--;q--;
			int cost;
			scanf("%s",in);
			if(in[0]=='x')cost=-1;
			else sscanf(in,"%d",&cost);
			g[p].push_back(make_pair(q,cost));
			g[q].push_back(make_pair(p,cost));
		}
		for(int i=0;i<1100;i++)for(int j=0;j<110;j++){
			ijk[i][j]=9999999999999999LL;
			v[i][j]=0;
		}
		priority_queue<pair<long long,pair<int,int> > >Q;
		Q.push(make_pair(0,make_pair(e,0)));
		ijk[e][0]=0;
		while(Q.size()){
			long long cost=-Q.top().first;
			int at=Q.top().second.first;
			int x=Q.top().second.second;
			Q.pop();
			if(v[at][x])continue;
if(x>100)continue;
			v[at][x]=1;
//printf("%d %d %lld\n",at,x,cost);
			for(int i=0;i<g[at].size();i++){
				int to=g[at][i].first;
				int tx=x;
				long long tmp=cost;
				if(g[at][i].second==-1){
					tx++;
				}else tmp+=g[at][i].second;
				if(!v[to][tx]&&ijk[to][tx]>tmp){
					ijk[to][tx]=tmp;
//printf("%lld %d %d\n",tmp,to,tx);
					Q.push(make_pair(-tmp,make_pair(to,tx)));
				}
			}
		}
	//	for(int i=0;i<10;i++)printf("%lld %lld\n",ijk[c][i],ijk[d][i]);
		long long ret=99999999999999999LL;
		for(int i=0;i<110;i++)for(int j=0;j<110;j++){
		//	if(i&&ijk[c][i]>=ijk[c][i-1])continue;
		//	if(j&&ijk[d][j]>=ijk[d][j-1])continue;
			bool dame=false;
			for(int k=0;k<i;k++)if(ijk[c][k]<=ijk[c][i])dame=true;
			for(int k=0;k<j;k++)if(ijk[d][k]<=ijk[d][j])dame=true;
			if(dame)continue;
			if(ijk[c][i]>=9999999999999999LL)continue;
			if(ijk[d][j]>=9999999999999999LL)continue;
 
			long long L=0;
			long long R=9999999999999LL;
 
			for(int k=0;k<110;k++){
				if(i!=k&&ijk[c][k]!=9999999999999999LL){
					long long t1=ABS(ijk[c][k]-ijk[c][i]);
					long long c1=t1/ABS(i-k);
					
					if(k<i){
						if(ijk[c][k]>=ijk[c][i])R=min(R,c1);
					}else{
						if(ijk[c][k]<=ijk[c][i])L=max(L,c1+(t1%ABS(i-k)?1:0));
					}
				}
				if(j!=k&&ijk[d][k]!=9999999999999999LL){
					long long t1=ABS(ijk[d][k]-ijk[d][j]);
					long long c1=t1/ABS(j-k);
					if(k<j){
						if(ijk[d][k]>=ijk[d][j])R=min(R,c1);
					}else{
						if(ijk[d][k]<=ijk[d][j])L=max(L,c1+(t1%ABS(j-k)?1:0));
					}
				}
			}
		//	printf("%d %d: %lld %lld %lld\n",i,j,L,R,ret);
			if(L>R)continue;
			
			ret=min(ret,ABS(L*i+ijk[c][i]-L*j-ijk[d][j]));
			ret=min(ret,ABS(R*i+ijk[c][i]-R*j-ijk[d][j]));
			if(i!=j){
				long long t2=ABS(ijk[c][i]-ijk[d][j]);
				long long c2=t2/ABS(i-j);
				if(L<=c2&&c2<=R)ret=min(ret,ABS(c2*i+ijk[c][i]-c2*j-ijk[d][j]));
				if(L<=c2+1&&c2+1<=R)ret=min(ret,ABS(c2*i+i+ijk[c][i]-c2*j-j-ijk[d][j]));
			}
			
		}
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 4268
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a <= b&&b <= c)
		printf("%d %d %d", a, b, c);
	else if (a <= c&&c <= b)
		printf("%d %d %d", a, c, b);
	else if (b <= a&&a <= c)
		printf("%d %d %d", b, a, c);
	else if (b <= c&&c <= a)
		printf("%d %d %d", b, c, a);
	else if (c <= a&&a <= b)
		printf("%d %d %d", c, a, b);
	else if(c<=b&&b<=a)
		printf("%d %d %d", c, b, a);

	printf("\n");

	return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)

int D = 365;
vi c, ans;
vvi s;

void input() {
  cin >> D;
  c = vi(26);
  s = vvi(D, vi(26));
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
}

int simulate(vi a, int day) {
  int sum = 0;
  vi last(26, 0);
  for (int i = 0; i <= day; i++) {
    sum += s[i][a[i]];
    last[a[i]] = i + 1;
    for (int j = 0; j < 26; j++) {
      sum -= c[j] * (i - last[j] + 1);
    }
  }
  return sum;
  // return max((int)1e6 + sum, 0);
}

int simulate(vi a) {
  return simulate(a, D - 1);
  //   return max((int)1e6 + simulate(a, D - 1), 0);
}

int main() {
  input();

  vi t(D);
  for (ll i = 0; i < D; i++) {
    cin >> t[i];
    t[i]--;
  }

  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int d, q;
    cin >> d >> q;
    d--, q--;
    t[d] = q;
    cout << simulate(t) << endl;
  }
}


Measured memory_bytes: 3680
#include<stdio.h>
#include<stdlib.h>

int main(){
	int n, k;
	int *ball, *cnt;
	long long sum = 0, ans;

	scanf("%d", &n);

	ball = (int *)malloc(sizeof(int)*n);
	cnt = (int *)malloc(sizeof(int)*n);
	for(k=0; k<n; k++){
		cnt[k] = 0;
	}

	for(k=0; k<n; k++){
		scanf("%d", ball+k);
		cnt[ball[k]-1]++;
	}

	for(k=0; k<n; k++){
		sum += (long long)cnt[k]*(cnt[k]-1)/2;
	}

	for(k=0; k<n; k++){
		ans = sum - (cnt[ball[k]-1] - 1);
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  map<ll,int> mp;
  ll tmp;
  rep(i,N){
    cin >> tmp;
    mp[tmp]++;
  }
  vector<ll> OKlen;
  for(auto x:mp){
    if(x.second>=2){
      OKlen.pb(x.first);
    }
    if(x.second>=4){
      OKlen.pb(x.first);
    }
  }
  sort(all(OKlen),greater<ll>());
  if((int)OKlen.size()<2) cout << 0 << endl;
  else cout << OKlen[0] * OKlen[1] << endl;
  return 0;
}


Measured memory_bytes: 6528
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	for(ll i=0;i<n;i++){
		cin >> a[i];
	}
	ll s=0;
	ll c=1000;
	for(ll i=0;i<n-1;i++){
		if(s==0){
			s= c/a[i];
			c= c-s*a[i];
		}
		if(a[i+1]<a[i]){
			c+=s*a[i];
			s=0;
		}
	}
	if(s!=0){
		c+=s*a[n-1];
	}
	cout << c << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t; cin >> s >> t;
    vi start(26, -1);
    vi goal(26, -1);
    rep (i, s.size()) {
        int a = s[i] - 'a';
        int b = t[i] - 'a';

        if (start[a] != -1 || goal[b] != -1) {
            if (start[a] != b || goal[b] != a) {
                COUT("No");
                return 0;
            }
        }
        else {
            start[a] = b;
            goal[b] = a;
        }
    }
    COUT("Yes");
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

int main() {
	fastIO;
#ifdef LOCAL
			freopen("input.in", "rt", stdin);
#endif
	string a, b;
	cin >> a >> b;
	b.pop_back();
	if(a == b) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 3648
N = int(input())
A = list(map(int ,input().split()))

cnt = 0
for i in range(N):
    if A[i] < 0:
        cnt += 1
        A[i] = -1 * A[i]
if cnt % 2 == 0:
    print(sum(A))
else:
    A.sort()
    print(sum(A) - A[0] * 2)

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

int main() {
  int N, A;
  cin >> N >> A ;
  if ((N % 500) == 0)
    cout << "Yes" << endl;
  else if(A-((N - (N / 500 * 500 ))) >=0)
  	cout << "Yes" << endl;
  else
	cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
#define INF 1000000007
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    int ans=0;
    for(int i=1;i<=m/n;++i)
    for(int i=m/n;i>=1;--i)
    {
        if(m%i==0)
        {
            int g=m/i;
            if(g>=n)
                return cout<<i<<endl,0;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,a[N],dp[N];
vector<ll> vt[N];
vector<pair<ll,ll> > vp;
struct Segt{
	ll l,r,val;
}segt[4*N];
void build_tree(ll x,ll l,ll r)
{
	if(l>r)
	{
		return;
	}
	segt[x].l=l;
	segt[x].r=r;
	segt[x].val=0;
	if(l==r)
	{
		return;
	}
	ll mid=(l+r)>>1,aa=x<<1;
	build_tree(aa,l,mid);
	build_tree(aa+1,mid+1,r);
	return;
}
void update(ll x,ll l,ll v)
{
	ll tl=segt[x].l,tr=segt[x].r;
	if(tr<l||tl>l)
	{
		return;
	}
	if(tl==l&&tr==l)
	{
		segt[x].val=v;
		return;
	}
	ll mid=(tl+tr)>>1,aa=x<<1;
	if(mid>=l)
	{
		update(aa,l,v);
	}
	else
	{
		update(aa+1,l,v);
	}
	segt[x].val=max(segt[aa].val,segt[aa+1].val);
	return;
}
ll getans(ll x,ll l,ll r)
{
	ll tl=segt[x].l,tr=segt[x].r;
	if(l>r||tl>r||tr<l)
	{
		return 0;
	}
	if(tl>=l&&tr<=r)
	{
		return segt[x].val;
	}
	ll mid=(l+r)>>1,aa=x<<1,ret=0;
	if(mid>=l)
	{
		ret=max(ret,getans(aa,l,r));
	}
	if(mid<r)
	{
		ret=max(ret,getans(aa+1,l,r));
	}
	return ret;
}
void dfs(ll x,ll lst)
{
	ll pos=lower_bound(vp.begin(),vp.end(),make_pair(a[x],(ll)-1))-vp.begin();
	ll pos2=lower_bound(vp.begin(),vp.end(),make_pair(a[x],x))-vp.begin();
	ll val1=getans(1,0,pos-1),val2=getans(1,pos,n-1),i;
	//cout<<x<<" "<<pos<<" "<<val1<<" "<<val2<<endl;
	dp[x]=max(val1+1,val2);
	update(1,pos2,val1+1);
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs(vt[x][i],x);
		}
	}
	update(1,pos2,0);
	return;
}
int main(){
	ll i,x,y;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		vp.push_back(make_pair(a[i],i));
	}
	for(i=1;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	sort(vp.begin(),vp.end());
	build_tree(1,0,n-1);
	dfs(0,-1);
	for(i=0;i<n;i++)
	{
		printf("%lld\n",dp[i]);
	}
	return 0;
}

Measured memory_bytes: 49844
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();
		String ans;
		if (a + b == 15) {
			ans = "+";
		} else if (a * b == 15) {
			ans = "*";
		} else {
			ans = "x";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,num=0,min=1000000;
	cin>>n>>x;
	int a[n+2];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		x-=a[i];
		num++;
		if(min>a[i]) min=a[i];
	}
	num+=x/min;
	cout<<num;
	return 0;
} 

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

 int main()
 {
     int t;
     scanf("%d",&t);
     vector< int > p;
     int ar[20000];
     int r;
     int q;
     int count =0;
     for(int i=0; i<t; i++)
     {
         scanf("%d",&r);
         if(r == 2)
         {
             count--;
             p.erase(p.begin()+count);
         }
         else
         {
             scanf("%d",&q);
             if(r == 1) cout << p[q] << endl;
             else
             {
                 p.push_back(q);
                 count++;
             }
         }
     }
 }



Measured memory_bytes: 3916
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define N 100005
using namespace std;
int a[N],b[N],n,m,d[N],c[N],n1,f[N];
map <int,int> h;
bool bz[N];
int getf(int k)
{
    if(f[k]==0||f[k]==k) return k;
    return (f[k]=getf(f[k])); 
}
int main()
{
    cin>>n;
    int v=0;
    fo(i,1,n) scanf("%d",&a[i]),v^=a[i],c[i]=a[i];
    a[n+1]=c[n+1]=v;
    bool pd=0;
    v=0;
    fo(i,1,n) scanf("%d",&b[i]),d[i]=b[i],v^=b[i];
    b[++n]=d[n]=v;
    sort(c+1,c+n+1),sort(d+1,d+n+1);
    n1=0;
    fo(i,1,n) 
    {
        if(c[i]!=d[i]) 
        {
            printf("-1\n");
            return 0;
        }
        if(h.count(c[i])==0) h[c[i]]=++n1;
        if(h.count(d[i])==0) h[d[i]]=++n1; 
    }
    int ans=0;
    fo(i,1,n) 
    {
        a[i]=h[a[i]],b[i]=h[b[i]];
        if(a[i]!=b[i]) 
        {
            if(i<n) ans++;
            int fx=getf(a[i]),fy=getf(b[i]);
            f[fx]=fy;
            bz[fx]=1,bz[fy]=1;
        }
    }
    if(ans==0) printf("0\n");
    else
    {
        bz[a[n]]=bz[b[n]]=1;
        fo(i,1,n1) if(bz[i]&&getf(i)==i) ans++;
        printf("%d\n",ans-1);
    }
}

Measured memory_bytes: 8576
#include <iostream>

int main(void){
    using namespace  std;
    long A, B, K;
    cin >> A >> B >> K;
    if(K>A){
        K -= A;
        A = 0;
        if(K>B){
            B = 0;
            K -= B;
        } else{
            B -= K;
        }
    } else {
        A -= K;
    }
    
    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {

    int cards[4][13];
    int n,num,i,j;
    char m,d;

    for(i=0; i < 4; i++){
        for(j=0; j < 14; j++){
            cards[i][j]=0;
        }
    }

    scanf("%d",&n);

    for(i = 0; i < n; i++){
        scanf("%c", &d);

        scanf("%c %d", &m, &num);
        if(m == 'S'){
            cards[0][num-1] = 1;
        }
        else if(m == 'H'){
            cards[1][num-1] = 1;
        }
        else if(m == 'C'){
            cards[2][num-1] = 1;
        }
        else if(m == 'D'){
            cards[3][num-1] = 1;
        }
    }

    for(i = 1; i < 5; i++){
        if(i == 1){
            m = 'S';
        }else if(i == 2){
            m = 'H';
        }else if(i == 3){
            m = 'C';
        }else if(i == 4){
            m = 'D';
        }
        for(j = 1; j < 14; j++){
            if(cards[i-1][j-1] == 0){
                printf("%c %d\n",m,j);
            }
        }
    }

    return 0;
}



Measured memory_bytes: 2100
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		int n;
		scanf("%d",&n);
		int a[n];
		for (int i=0 ; i<n ; i++) scanf("%d",&a[i]);
		ll taka = 1000;
		for (int i=0 ; i<n-1 ; i++)
		{
			ll stocks = 0;
			if(a[i]<a[i+1]) stocks = taka/a[i];
			taka+=(a[i+1]-a[i])*stocks;
		}
		printf("%lld\n",taka);
		return 0;  
}  


Measured memory_bytes: 3848
#最長増加部分列問題 (LIS) 
import bisect

N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = int(input())

LIS = [-1] * N
LIS[-1] = seq[0]
#print(LIS)
for i in range(1, len(seq)):
    LIS[bisect.bisect_left(LIS, seq[i]) - 1] = seq[i]
    #print(LIS)
#print(LIS)
c = LIS.count(-1)
print(len(LIS) - c)

Measured memory_bytes: 47192
import java.util.Arrays; 
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static interface Expr{
	  	public int eval(int[] bits, int[] types);
	}
	
	public static final int AND = 0;
	public static final int OR  = 1;
	public static final int SUB = 2;
	
	public static class Node implements Expr{
		int number;
		Expr left, right;
		
		public Node(int n, Expr l, Expr r){
			number = n;
			left = l;
			right = r;
		}
		
		public int eval(int[] bits, int[] types){
			if(types[number] == AND){
				//System.out.println("And : " + (Integer.toBinaryString(left.eval(bits, types) & right.eval(bits, types))));
				return left.eval(bits, types) & right.eval(bits, types);
			}else if(types[number] == OR){
				//System.out.println("Or : " + (Integer.toBinaryString(left.eval(bits, types) | right.eval(bits, types))));
				return left.eval(bits, types) | right.eval(bits, types);
			}else if(types[number] == SUB){
				return left.eval(bits, types) ^ right.eval(bits, types);
			}else{
				return Integer.MIN_VALUE;
			}
		}
	}
	
	public static class Var implements Expr{
		int number;
		
		public Var(int n){
			number = n;
		}
		
		public int eval(int[] bits, int[] types){
			return bits[number];
		}
	}
	
	
	public static int node_number = 0;
	public static Expr parse(char[] input, int start, int end){
		if(input[start] == '('){
			int kakko_lv = 1;
			int kakko_end = -1;
			int space_pos = -1;
			
			for(int pos = start + 1; pos <= end; pos++){
				if(input[pos] == '('){
					kakko_lv++;
				}else if(input[pos] == ')'){
					kakko_lv--;
					if(kakko_lv == 0){
						kakko_end = pos;
						break;
					}
				}else if(kakko_lv == 1 && input[pos] == ' '){
					space_pos = pos;
				}
			}
			node_number++;
			return new Node(node_number - 1, parse(input, start + 1, space_pos - 1), parse(input, space_pos + 1, kakko_end - 1));
		}else{
			return new Var((int)(input[start] - '0') - 1);
		}
	}
	
	public static int dps(int nodes, int n, int deep, int[] bits, int[] types, Expr expr){
		if(nodes <= deep){
			int ret = expr.eval(bits, types);
			//System.out.println(Arrays.toString(types));
			if(ret == (1 << 4) - 1){
				return 1;
			}else{
				return 0;
			}
			
			
		}else{
			int ret = 0;
			
			for(int i = 0; i < 3; i++){
				types[deep] = i;
				//System.out.println(deep + " " + i);
				ret += dps(nodes, n, deep + 1, bits, types, expr);
			}
			
			return ret;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			node_number = 0;
			
			String input = sc.nextLine();
			if(input.equals("END")){
				break;
			}
			
			final int n = Integer.parseInt(sc.nextLine());
			
			int bits[] = new int[n];
			for(int i = 0; i < n; i++){
				String[] inputs = sc.nextLine().split(" ");
				
				int count = 0;
				for(String ins : inputs){
					int bit = Integer.parseInt(ins);
					
					bits[i] += bit << count;
					count++;
				}
			}
						
			Expr expr = parse(input.toCharArray(), 0, input.length() - 1);

			int[] types = new int[node_number];
			System.out.println(dps(node_number, n, 0, bits, types, expr));
		}
		
	}
}

Measured memory_bytes: 46392