akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int res = 0;
	int H = 0;
	for (int i = 0; i < n; i++) {
		if (h[i] >= H) {
			res++;
			H = h[i];
		}
	}
	cout << res << endl;
}

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 h, n;
    cin >> h >> n;
    int a, tot = 0;
    rep(i, n) {
        cin >> a;
        tot += a;
    }
    if (tot >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const double INF = 1e18;
const int MAX = 1000004;

int N,M;
int b[5];
char fu[5];

int DP(int n,int sum)
{
    if(n==4&&sum==7)
        return 1;
    else if (n>=4)
        return 0;

    fu[n] = '-';
    if(DP(n+1,sum-b[n+1]))
        return 1;
    fu[n] = '+';
    if(DP(n+1,sum+b[n+1]))
        return 1;
}

int main()
{
    char a[4];
    cin>>a;
    for(int i = 0;i<4;i++)
        b[i+1] = a[i]-'0';
    DP(1,b[1]);

    for(int i = 1;i<=3;i++)
    {
        cout<<b[i]<<fu[i];
    }
    cout<<b[4]<<"=7"<<endl;

    return 0;
}


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

typedef long long int llint;

int main()
{
  int n, k;
  int a[100001];
  
  cin>> n >> k;
  for(int i = 0; i < n; i++) {
    cin>> a[i];
  }

  int cnt = (n - 1) / (k - 1);

  if((n - 1) % (k - 1) > 0) cnt++;

  cout<< cnt <<endl;

  return 0;
}


Measured memory_bytes: 640
local function gcd(a,b)
	return b>0 and gcd(b,a%b) or a
end

----------

local n=io.read("n")
local a={}
for i=1,n do
	a[i]=io.read("n")
end

local t={1}
for i=2,1000000 do
	if not t[i] then
		for j=1,math.floor(1000000/i) do
			t[i*j]=i
		end
	end
end

local s={}
local pw=true
for i=1,n do
	local A=a[i]
	local T={}
	while A>1 do
		if not T[t[A]] then 
			T[t[A]]=true
		end
		A=math.floor(A/t[A])
	end
	for p in pairs(T) do
		if not s[p] then
			s[p]=true
		else
			pw=false
		end
	end
end

if pw then
	print("pairwise coprime")
else
	local sw=a[1]
	for i=2,n do
		sw=gcd(sw,a[i])
	end
	if sw==1 then
		print("setwise coprime")
	else
		print("not coprime")
	end
end


Measured memory_bytes: 44932
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> a(N);
  
  int sum = 0;
  
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  
  int ans = sum;
  int pre_sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    pre_sum += a[i];
    ans = min(ans, abs(pre_sum - (sum - pre_sum)));
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include <stdio.h>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define P complex<ld>
#define X real()
#define Y imag()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1000000000000000009
using namespace std;
//freopen("output.txt", "w", stdout);
//freopen("input.txt", "r", stdin);
const int mod = 1000000007;
const int N = 2 * 100000 + 9;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (ll &A, ll &B){
		return A > B;
	}
};
bool by_sec(const pll &a, const pll &b){
	if ((abs(a.first) == abs(b.first)))
		return (abs(a.second) < abs(b.second));
	return (abs(a.first) < abs(b.first));
}
bool byth(const tuple<ll, ll, ld>& a, const tuple<ll, ll, ld>& b){
	return (get<2>(a) < get<2>(b));
}
ld dist(P a, P b){
	return (ld)abs(a - b);
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll max(ll a, ll b){
	if (a >= b)return a;
	else return b;
}
ll min(ll a, ll b){
	if (a <= b)return a;
	else return b;
}

vvll gr(N);
bool vis[N][4];
vll en;
void dfs(ll n, ll c){
	vis[n][c] = 1;
	if (c == 0){
		if (!vis[n][3]){
			vis[n][3] = 1;
			en.push_back(n);
		}
		return;
	}
	for (auto i : gr[n]){
		if (!vis[i][c-1])
		dfs(i, c - 1);
	}
}

int main()
{
	Amr_Abdelazim

		ll n, m;
	cin >> n >> m;
	rep(i, m){
		ll a, b;
		cin >> a >> b;
		gr[a].push_back(b);
	}
	ll s, t;
	cin >> s >> t;
	dfs(s, 3);
	vis[s][3] = 1;
	ll lv = 1;
	bool bb = 1;
	while (bb){
		vll st = en;
		en.clear();
		bb = 0;
		for (auto i : st){
			if (i == t){
				cout << lv << "\n";
				return 0;
			}
			bb = 1;
			dfs(i, 3);
		}
		lv++;
	}
	cout << "-1\n";
	return 0;
}

Measured memory_bytes: 11456
//-----------------------
// author : xyqkoala
// time : 2020-07-01
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	int n;
	cin>>n;
	LL res = 0;
	vector<int> dp(n+1,1);
	for(int i=1;i<=n;i++){
		int cnt = n/i;
		res += 1ll *i* (cnt+1)*cnt/2;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 42284
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,i,j,k,l,m;
    cin >> n;
    vector<ll> Data;
    ll tot = 0;
    for (i = 1;i<=n;i++){
        cin >> k;
        Data.pb(k);
        tot ^= k;
    }
    for (i = 0; i < n;i++){
        cout << (Data[i]^tot)<<" ";
    }
    return 0;
}

Measured memory_bytes: 5312
#include<stdio.h>
int main()
{
	int a;
	int b;
	int c;
	int d;
	int s;
	scanf("%d",&s);
	a=s%10;
	b=s/10%10;
	c=s/100%10;
	d=s/1000;
	if(a!=b&&b!=c&&c!=d){
		printf("Good\n");
	}
	else{
		printf("Bad\n");
	}
	
	return 0;
}

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

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

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

		if(A==B&&A!=C) {
			System.out.println("Yes");
		} else {
			if(A==C&&A!=B) {
				System.out.println("Yes");
			} else {
				if(B==C&&B!=A) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}
			}
		}

	}
}


Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int a,b;
  for(int i=0;i<s.size();i++){
    if(s[i]=='Z')b=i;
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='A')a=i;
  }
  cout<<b-a+1<<endl;
  return(0);
}


Measured memory_bytes: 640
// inputに入力データ全体が入る
function Main(input) {
  input = input.split(" ");
  var K = Number(input[0]); //個数
  var X = Number(input[1]); //座標
  var array = [];

  for(var i = X-K+1; i < X+K; i++){
    array.push(i);
  }
  console.log(array.join(' '));
  

 }
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
const int N=1e3;
int main(){
	ios::sync_with_stdio(0);
	int a[10],b[10];
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
        scanf("%d%d",&a[i],&b[i]);
    double s=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        s+=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
    s=s*2/n;
    printf("%.10f\n",s);
	return 0;
}


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

 
int main()
{
string s;
cin>>s;
string s2="ARC";
string s3="ABC";
if(s[1]=='R'){
    cout<<s3<<endl;
}
else{
    cout<<s2<<endl;
}

   return 0;
}



Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		long ans = 0;
		for(int i = 0 ; i < s.length() - 1 ; i++) {
			if(s.charAt(i) != '9') {
				long temp = Long.valueOf(s);
				long math = Long.valueOf((s.substring(0 + i + 1))) + 1;
				ans = Math.max(ans, func(temp - math));
			}
		}
		ans = Math.max(ans, func(Long.valueOf(s) - Long.valueOf(s) % 10 - 1));
		ans = Math.max(ans, func(Long.valueOf(s)));
		System.out.println(ans);
	}

	public static long func(long x) {
		long wa = 0;
		while(x >= 1) {
			wa += x % 10;
			x = x / 10;
		}
		return wa;
	}

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

bool isPalin(string s){
    rep(i,s.size()){
        if(s[i]!=s[s.size()-1-i]) return false;
    }
    return true;
}

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

    string s;cin>>s;
    int n=(int)s.size();
    if(!isPalin(s)){
        cout<<"No"<<endl;
        return 0;
    }
    if(!isPalin(s.substr(0,(n-1)/2))){
        cout<<"No"<<endl;
        return 0;
    }
    if(!isPalin(s.substr((n-1)/2+1,(n-1)/2))){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
import string
import math
n = int(input())
ans = []
ans1= []
count=1
while n>0:
    ans.append(n%26)
    n-=26
    n=math.ceil(n/26)
ans.reverse()
for i in ans:
    ans1.append(string.ascii_lowercase[i-1])

print("".join(ans1))

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	int a[n+5];
	int b[n+5];
	rep(i,1,n+1)
	{
		cin >> a[i];
	}
	rep(i,1,n)
	{
		cin >> b[i];
	}
	int ans=0;
	rep(i,1,n)
	{
		int x= min(a[i],b[i]);
		ans += x;
		b[i] = b[i] - x;
		x= min(a[i+1],b[i]);
		ans += x;
		a[i+1]= a[i+1] - x;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define vi vector<int>
using namespace std;
int main(void)
{
   int n;
   cin>>n;
   vi h(n);
   vi dp(n);
   for(int  i = 0;i<n;i++)
   {
      dp[i] =INT_MAX;
      cin>>h[i];
   }
   dp[0]=0;
   for(int  i = 0;i<n;i++)
   {
        if((i+1)<n)
          dp[i+1] = min(dp[i+1],(dp[i]+abs(h[i+1]-h[i])));
        if((i+2)<n)
          dp[i+2] = min(dp[i+2],(dp[i]+abs(h[i+2]-h[i])));
   }
   cout<<dp[n-1]<<endl;
}





























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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n;
    cin1(n);
    if (n == 1) {
        cout << "Hello World" << endl;
        return 0;
    }
    lli a, b;
    cin2(a,b);
    cout << a+b<<endl;
}


Measured memory_bytes: 764
package main

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

func main() {
	resolve(parseProblem(os.Stdin))
}

func parseProblem(r io.Reader) *graph {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	n, m := scanInt(sc), scanInt(sc)
	g := scanGraph(n, m, sc)
	return g
}

type graph struct {
	size  int
	edges []nodeSet
}

func newGraph(n int) *graph {
	g := &graph{
		size:  n,
		edges: make([]nodeSet, n),
	}
	for i := 0; i < n; i++ {
		g.edges[i] = newSet()
	}
	return g
}

func scanGraph(n, m int, sc *bufio.Scanner) *graph {
	g := newGraph(n)
	for i := 0; i < m; i++ {
		x, y := scanInt(sc), scanInt(sc)
		// 0-indexed
		x--
		y--
		g.addEdge(x, y)
	}
	return g
}

func (g *graph) addEdge(x, y int) {
	g.edges[x].add(y)
	g.edges[y].add(x)
}

func (g *graph) addDirectedEdge(x, y int) {
	g.edges[x].add(y)
}

func (g *graph) exists(x, y int) bool {
	return g.edges[x].doesContain(y)
}

type nodeSet map[int]none

func newSet() nodeSet {
	return make(map[int]none)
}

func (s nodeSet) add(item int) {
	s[item] = mark
}

func (s nodeSet) doesContain(item int) bool {
	_, ok := s[item]
	return ok
}

func (s nodeSet) size() int {
	return len(s)
}

func (s nodeSet) members() (l []int) {
	for k := range s {
		l = append(l, k)
	}
	return l
}

var mark none

type none struct{}

func resolve(g *graph) {
	// g is 0-indexed
	parents := make([]int, g.size)
	for i := 0; i < len(parents); i++ {
		parents[i] = -1
	}
	parents[0] = 0
	q := []int{0}
	// BFS
	for len(q) > 0 {
		cur := q[0]
		q = q[1:]
		for k := range g.edges[cur] {
			if parents[k] != -1 {
				continue
			}
			parents[k] = cur
			q = append(q, k)
		}
	}
	// resolved
	fmt.Println("Yes")
	for i := 1; i < len(parents); i++ { // start from 2
		// recover to 1-indexed
		fmt.Println(parents[i] + 1)
	}
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
  int x,y,ans = 0;
  cin >> x >> y;
  if(x == 1) ans += 3e5;
  if(x == 2) ans += 2e5;
  if(x == 3) ans += 1e5;
  if(y == 1) ans += 3e5;
  if(y == 2) ans += 2e5;
  if(y == 3) ans += 1e5;
  if(x == 1 && y == 1) ans += 4e5;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
long long n;cin>>n;
if(n%11>6)cout<<(n/11)*2+2;
else if(n%11>0)cout<<(n/11)*2+1;
else cout<<(n/11)*2;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;

int main()
{
	int32_t W, a, b;
	cin >> W >> a >> b;

	int32_t res = 0;
	if (a < b) {
		if (a + W < b)
			res = b - (a + W);
	} else {
		if (b + W < a)
			res = a - (b + W);
	}

	cout << res  << endl;

	return 0;
}

Measured memory_bytes: 256
A=input()
N=len(A)
alphabet=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
alp_to_n={}
for i,l in enumerate(alphabet):
  alp_to_n[l]=i
  
D=[True]*26
L=[N]
s=0
for i in range(N)[::-1]:
  if D[alp_to_n[A[i]]]:
    D[alp_to_n[A[i]]]=False
    s+=1
  if s==26:
    D=[True]*26
    L.append(i)
    s=0
L.reverse()
ans=[]
D=[True]*26
for i in range(0,L[0]):
    D[alp_to_n[A[i]]]=False
    
for i in range(len(L)-1):
  num,pos=26,0
  for j in range(L[i],L[i+1]):
    if alp_to_n[A[j]]<num and D[alp_to_n[A[j]]]:
      num=alp_to_n[A[j]]
      pos=j
  ans.append(alphabet[num])
  D=[True]*26
  for j in range(pos+1,L[i+1]):
    D[alp_to_n[A[j]]]=False
for i in range(26):
  if D[i]:
    ans.append(alphabet[i])
    break
print("".join(ans))
  
      
  
  

Measured memory_bytes: 43744
let rec solve a b c x =
    if x = 0 then 1 else
        if 500 * a + 100 * b + 50 * c = x then 1 else
            (if x >= 500 && a >= 1 then solve (a - 1) b c (x - 500) else 0)
            + (if x >= 100 && b >= 1 then solve 0 (b - 1) c (x - 100) else 0)
            + (if x >= 50  && c >= 1 then solve 0 0 (c - 1) (x - 50)  else 0)

let () =
    let a = read_int () in
    let b = read_int () in
    let c = read_int () in
    let x = read_int () in
    print_int (solve a b c x);
    print_newline ()


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector <int> adj[100005],dp;
int dfs(int v)
{
    if(dp[v]!=-1)
    return dp[v];
    dp[v]=0;
    for(int e: adj[v])
    {
        dp[v]=max(dp[v],dfs(e)+1);
    }
return dp[v];
}
int main()
{
    cin>>n>>m;
    dp.resize(n+1,-1);
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
    }
    for(int i=1;i<=n;i++)
    {
        dfs(i);
    }
    int mx=0;
    for(int i=0;i<=n;i++)
    {
        mx=max(dp[i],mx);
    }
    cout<<mx<<endl;
return 0;
}

Measured memory_bytes: 8192
import fractions
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
r=[0]*(n+1)
for i in range(n):
  l[i+1]=fractions.gcd(l[i],a[i])
for i in reversed(range(n)):
  r[i]=fractions.gcd(r[i+1],a[i])

A=[fractions.gcd(l[i],r[i+1]) for i in range(n)]
print(max(A))


Measured memory_bytes: 16124
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    S = LI()

    cnt = [0]

    def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        L.append(INF)
        R.append(INF)
        i = 0
        j = 0
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 1

    def mergeSort(A, left, right):
        if left+1 < right:
            mid = (left+right)//2
            mergeSort(A, left, mid)
            mergeSort(A, mid, right)
            merge(A, left, mid, right)

    mergeSort(S, 0, n)
    print(*S)
    print(cnt[0])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 61676
def calc_mp(ls, target):
    ret = 0
    ret += 10 * (len(ls) - 1)
    val = sum(ls)
    ret += abs(val - target)
    return ret


n, a, b, c = map(int, input().split())
l_ls = []
for i in range(n):
    l_ls.append(int(input()))

pattern = []

for i in range(4 ** n):
    tmp = [0] * n
    val = i
    for j in range(n):
        tmp[j] = val % 4
        val = val // 4
    pattern.append(tmp)

ret = 10 ** 100

for item in pattern:
    if 1 not in item or 2 not in item or 3 not in item:
        continue
    else:
        ones = []
        twos = []
        threes = []
        for i in range(n):
            if item[i] == 1:
                ones.append(l_ls[i])
            elif item[i] == 2:
                twos.append(l_ls[i])
            elif item[i] == 3:
                threes.append(l_ls[i])
        mp = 0
        mp += calc_mp(ones, a)
        mp += calc_mp(twos, b)
        mp += calc_mp(threes, c)
        ret = min(ret, mp)

print(ret)


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

using namespace std;

int main()
{
    int N;
    cin>>N;
    int count = 0;
    for(int i = N - 1; i > 0; i--)
    {
        for(int a = 1 ; a <= sqrt(i); a++)
        {
            if(a*a == i)
            {   count++;
                break;
            }
            if(i%a == 0)
                count+= 2;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 3672
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	for(int i=0;i<3;++i){
		string str;
		cin>>str;
		cout<<str[i];
	}
	cout<<endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define PI 3.141592653

int main(){
    int n;
    double x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4,x_5,y_5,slope_1,slope_2,x,y,r;
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%lf%lf%lf%lf%lf%lf",&x_1,&y_1,&x_2,&y_2,&x_3,&y_3);
        
        if(y_1 - y_2 == 0){
            swap(x_2,x_3);
            swap(y_2,y_3);
        }
        if(y_2 - y_3 == 0){
            swap(x_1,x_2);
            swap(y_1,y_2);
        }
        
        slope_1=-(x_1-x_2)/(y_1-y_2);
        slope_2=-(x_3-x_2)/(y_3-y_2);
        
        x_4 = (x_1+x_2)/2;
        y_4 = (y_1+y_2)/2;
        
        x_5 = (x_3+x_2)/2;
        y_5 = (y_3+y_2)/2;

        x = ((slope_1*x_4-slope_2*x_5)-y_4+y_5)/(slope_1-slope_2);
        
        y = slope_1*x-slope_1*x_4+y_4;
        
        r = (x_1-x)*(x_1-x)+(y_1-y)*(y_1-y);
        
        printf("%.3lf %.3lf %.3lf\n",x,y,sqrt(r));
    }
    
    return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50


int main(){
    int N,M;
    cin>>N>>M;
    vector<int>p(N,0);
    REP(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        p[a]++;
        p[b]++;
    }
    bool f=true;
    REP(i,N)if(p[i]%2)f=false;
    if(f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

int main()
{
    int k, s,c=0;
    scanf("%d %d", &k, &s);
    for (int i=0; i <= k;i++)
    {
        for (int j=0; j <= k; j++) if(0<=s-i-j && s-i-j<=k) c++;
    }
    printf("%d\n",c);
    return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int a[100005];
ll suff[100005];

int main() {
	int n;
	scanf("%d", &n);
	for (int i=0 ; i<=n ; i++) {
		scanf("%d", a+i);
	}
	for (int i=n ; i>=0 ; i--) suff[i] = suff[i+1]+a[i];
	ll num = 1;
	ll sol = 0;
	for (int i=0 ; i<=n ; i++) {
	//	cout <<"num = "<<num<<endl;
		sol += num;
		if (a[i]>num) {
			printf("-1\n");
			return 0;
		}
		num -= a[i];
		num = min(num*2, suff[i+1]);
	}
	printf("%lld\n", sol);
	return 0;
}

Measured memory_bytes: 4984
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s1=list(input())
l=len(s1)
s2=groupby(s1)
now=0
for i in s2:
    now+=i[1]
    if i[1]!=1:
        print(str(now-i[1]+1)+" "+str(now))
        break
else:
    if l==2:
        print("-1 -1")
    else:
        for i in range(l-2):
            if s1[i]==s1[i+2]:
                print(str(i+1)+" "+str(i+3))
                break
        else:
            print("-1 -1")


Measured memory_bytes: 14116
#include<iostream>
#include<sstream>
using namespace std;
int one;

string itos(int a,int b){
  stringstream ss;
  string s;
  ss << (a+b)%10;
  return ss.str();
}

void rec(string s){
  string nes;
  for(int i=1;i<s.length();i++){
    nes+=itos(s[i-1]-'0',s[i]-'0');
  }
 
  if(nes.size() != 1)rec(nes);
  else one = nes[0]-'0';
}


int main(){
  string s;
  while(cin >> s){
    rec(s);
    cout << one << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

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

int main() {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> ps(A);
    rep(i,0,A) {
        cin >> ps[i];
    }
    vector<ll> qs(B);
    rep(i,0,B) {
        cin >> qs[i];
    }
    vector<ll> rs(C);
    rep(i,0,C) {
        cin >> rs[i];
    }
    sort(ps.begin(), ps.end());
    sort(qs.begin(), qs.end());
    sort(rs.begin(), rs.end());
    ll ans = numeric_limits<ll>::min();
    ll r_sum = 0;
    rep(i,0,min(C, X+Y)) {
        r_sum += rs[C-1-i];
    }
    ll pq_sum = 0;
    rrep(m,min(C, X+Y)+1,0) {
        ll left = X+Y - m;
        while (A - ps.size() + B - qs.size() < left) {
            if (A - ps.size() == X) {
                pq_sum += qs.back();
                qs.pop_back();
            } else if (B - qs.size() == Y) {
                pq_sum += ps.back();
                ps.pop_back();
            } else {
                if (ps.back() > qs.back()) {
                    pq_sum += ps.back();
                    ps.pop_back();
                } else {
                    pq_sum += qs.back();
                    qs.pop_back();
                }
            }
        }
        ans = max(ans, pq_sum + r_sum);
        if (m > 0) {
            r_sum -= rs[C-m];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
P = iil()
ans = 0
flag = False
for i in range(n-1):
    if flag:
        flag = False
        continue
    if P[i] == i+1:
        ans += 1
        flag = True
if P[-1] == n and flag == False:
    ans += 1
print(ans)


Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A,B,C;cin>>A>>B>>C;
    int K;cin>>K;
    while(K--){
        if(A>=B) B*=2;
        else C*=2;
    }
    
    if(C>B&&B>A) cout<<"Yes\n";
    else cout<<"No\n";
}





Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std; 
int main(){
  int n;  
  while(cin>>n){
    
    if(n==0)break;
    int a[200]={};
    int sum=0;
    for(int i=0;i<n;i++){    
      int b;
      cin>>b;
      a[i]=b;
      sum+=b;
    }
    sort(a,a+n);
    sum-=a[0];
    sum-=a[n-1];
    cout<<sum/(n-2)<<endl;
  }

  return 0;
}

Measured memory_bytes: 3004
import java.util.*;

public class Main {
    public static void main(String[] args ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int hpA = sc.nextInt();
        int atkA = sc.nextInt();
        int hpB = sc.nextInt();
        int atkB = sc.nextInt();

        boolean turn = true;
        while(turn){
            hpB -= atkA;
            if(hpB <= 0) break;
            hpA -= atkB;
            if(hpA <= 0) break;
        }
        if(hpA > hpB){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 27036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
void f(ll& a, ll& b) {
	if (a & 1) {
		--a;
	}
	b += a / 2;
	a /= 2;
}
void solve() {
	ll A[2], k;
	cin >> A[0] >> A[1] >> k;
	rep(i, 0, k) {
		f(A[i % 2 == 1], A[i % 2 == 0]);
	}
	print(A[0], A[1]);
}
int main() {
	solve();
	return 0;
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

string s;

int main(){
    cin >> s;

    for(int i = 1; i < s.length(); i++){
        if(s[i] == s[i-1]){
            cout << "Bad\n";
            return 0;
        }
    } 

    cout << "Good\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int pri=998244353;


template<int mod>
struct ModInt{
	int x;

	ModInt() : x(0){}
	ModInt(long long y) : x(y>=0 ? y%mod : (mod-(-y)%mod)){}

	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}

	ModInt operator-() const{return ModInt(-x);}
	ModInt operator+(const ModInt &p) const{return ModInt (*this)+=p;}
	ModInt operator-(const ModInt &p) const{return ModInt (*this)-=p;}
	ModInt operator*(const ModInt &p) const{return ModInt (*this)*=p;}
	ModInt operator/(const ModInt &p) const{return ModInt (*this)/=p;}
	bool operator==(const ModInt &p) const{return x==p.x;}
	bool operator!=(const ModInt &p) const{return x!=p.x;}
	friend ostream &operator<<(ostream &os, const ModInt &p){return os<<p.x;}
	friend istream &operator>>(istream &is,ModInt &a){
		int t;
		is>>t;
		a=ModInt<mod>(t);
		return (is);
	}

	ModInt inverse() const{
		int a=x, b=mod, u=1, v=0, t;
		while(b>0){
			t=a/b;
			a-=t*b;
			swap(a,b);
			u-=t*v;
			swap(u,v);
		}
		return ModInt(u);
	}
	
	ModInt pow(int e) const{
		long long a=1,p=x;
		while(e>0){
			if(e%2==0){p=(p*p)%mod; e/=2;}
			else {a=(a*p)%mod; e--;}
		}
		return ModInt(a);
	}
};

using modint=ModInt<pri>;
  vector<modint> frac(1000000,0);

modint ncr(int n,int r){
  return frac[n]/frac[r]/frac[n-r];
}

int mod_pow(int a,int N){
	if(N==0)return 1;
	if(N%2==1)return (a*mod_pow(a,N-1))%pri;
	int tmp=mod_pow(a,N/2);
  return (tmp*tmp)%pri;
}
signed main(){
  frac[0]=1;
  for(int i=1;i<200010;i++){
    frac[i]=i;
    frac[i]*=frac[i-1];
  }
  int N,M,K; cin>>N>>M>>K;
  modint ans=0;
  for(int i=0;i<K+1;i++){
    modint tmp=M;
    tmp*=mod_pow(M-1,N-i-1);
    tmp*=ncr(N-1,i);
    ans+=tmp;
  }
  cout<<ans<<endl;
}

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

int main(){
  ll n;cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);

  ll now = 1000;
  ll kabu = 0;
  rep(i,n-1){
    //株が安ければ買えるだけ買う
    if( a.at(i) < a.at(i+1) ){
      kabu += now/a.at(i);
      now %= a.at(i);
    }else if( a.at(i) > a.at(i+1) ){
      now += kabu*a.at(i);
      kabu = 0;
    }
  }
  ll ans = now + kabu*a.at(n-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  int N,K; cin>>N>>K;
  vector<ll> M,P;
  int Z=0;
  rep(i,N){
    ll A; cin>>A;
    if(A<0) M.push_back(-A);
    else if(A>0) P.push_back(A);
    else Z++;
  }
  sort(M.rbegin(),M.rend());
  sort(P.rbegin(),P.rend());
  ll ans=1;
  if(M.size()+P.size()<K){
    ans=0;
  }else if(M.size()+P.size()==K){
    for(ll m:M) (ans*=m)%=MOD;
    for(ll p:P) (ans*=p)%=MOD;
    if(K%2&&M.size()%2==1){
      if(K<N) ans=0;
      else ans*=-1;
    }
    if(K%2==0&&M.size()%2==1){
      if(K<N) ans=0;
      else ans*=-1;
    }
  }else if(M.size()==0){
    rep(i,K) (ans*=P[i])%=MOD;
  }else if(P.size()==0){
    if(K%2){
      if(Z) ans=0;
      else{
        int siz=M.size();
        rep(i,K) (ans*=M[siz-1-i])%=MOD;
        ans*=-1;
      }
    }else{
      rep(i,K) (ans*=M[i])%=MOD;
    }
  }else if(K==1){
    ans=P[0];
  }else{
    M.push_back(0);
    P.push_back(0);
    int m=0,p=0;
    rep(i,K){
      if(P[p]<M[m]) m++;
      else p++;
    }
    if(m%2==0){
      rep(i,m) (ans*=M[i])%=MOD;
      rep(i,p) (ans*=P[i])%=MOD;
    }else{
      ll tmp1,tmp2;
      if(p) tmp1=P[p-1]*P[p];
      else tmp1=LLONG_MAX;
      if(m) tmp2=M[m-1]*M[m];
      else tmp2=LLONG_MAX;
      if(tmp1<tmp2){
        rep(i,p-1) (ans*=P[i])%=MOD;
        rep(i,m+1) (ans*=M[i])%=MOD;
      }else{
        rep(i,p+1) (ans*=P[i])%=MOD;
        rep(i,m-1) (ans*=M[i])%=MOD;
      }
    }
  }
  cout<<(ans+MOD)%MOD<<endl;
  return 0;
}

Measured memory_bytes: 5508
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

template <typename T>
class Bit {
 public:
  Bit(int size) : size_(size) {
    data_.resize(size + 1);
  }

  // 0-indexed
  void add(int index, T value) {
    if (index < 0 || index >= size_) return;
    ++index;
    while (index <= size_) {
      data_[index] += value;
      index += index & -index;
    }
  }

  // [0, index]
  T sum(int index) {
    if (index < 0 || index >= size_) return 0;
    ++index;
    T ret = 0;
    while (index > 0) {
      ret += data_[index];
      index -= index & -index;
    }
    return ret;
  }

 private:
  std::vector<T> data_;
  int size_;
};

int n;

bool check(vi a, int x){
    for(auto& e : a) e = (e >= x ? 1:-1);
    a.emplace_back(0);

    int sum = n;
    Bit<int> bt(2 * n + 1);
    ll cnt = 0;
    rep(i, n + 1){
        cnt += bt.sum(sum);
        bt.add(sum, 1);
        sum += a[i];
    }

    ll N = 1LL * n * (n + 1) / 2;
    return cnt >= N - (N / 2 + 1) + 1;
}

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

    cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    int l = 0, r = (int)(1e9 + 11);
    rep(loop, 30){
        int mid = (l + r) / 2;

        if(check(a, mid)){
            l = mid;
        }
        else {
            r = mid;
        }
    }

    cout << l << endl;

    return 0;
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int A[3];
//---------------------------------------------------------------------------------------------------
void _main() {
    rep(i, 0, 3) cin >> A[i];

    int ans = inf;

    vector<int> ord;
    rep(i, 0, 3) ord.push_back(i);
    do {
        int a = A[ord[0]], b = A[ord[1]], c = A[ord[2]];
        int ab = abs(a - b);
        int bc = abs(b - c);
        chmin(ans, ab + bc);
    } while (next_permutation(all(ord)));

    cout << ans << endl;
}

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

const double BORROWING_AMOUNT = 100000;

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

    double value = BORROWING_AMOUNT;
    for (int i = 1; i <= n; ++i) {
        value += value * 0.05;
        int mod = (int) value % 1000;
        if (mod > 0) {
            value += 1000 - mod;
        }
    }
    cout << (int) value << endl;

    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int N = 200003;
long long d,f[N],g[N],a[N],ans=0;
int n;
int main(){
	scanf("%d%lld",&n,&d);
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		ans+=a[i];
	}
	f[1]=a[1];g[n]=a[n];
	for(int i=2;i<=n;i++) f[i]=min(f[i-1]+d,a[i]);
	for(int i=n-1;i>=1;i--) g[i]=min(g[i+1]+d,a[i]);
	for(int i=2;i<n;i++) ans+=min(f[i],g[i]);
	printf("%lld",ans+(n-1)*d);
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};


int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<tuple<llong, llong, llong> > Cake(n);
    rep(i, n) {
        llong x, y, z;
        cin >> x >> y >> z;
        Cake[i] = make_tuple(x, y, z);
    }

    vector<priority_queue<llong> > V(8);
    int cur = -1;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                ++cur;
                for (int l = 0; l < n; ++l) {
                    V[cur].push(pow(-1, i) * get<0>(Cake[l]) + pow(-1, j) * get<1>(Cake[l]) + pow(-1, k) * get<2>(Cake[l]));
                }
            }
        }
    }

    priority_queue<llong> A;
    llong tmp = 0;
    rep(i, 8) {
        rep(j, m) {
            tmp += V[i].top();
            V[i].pop();
        }
        A.push(tmp);
        tmp = 0;
    }

    cout << A.top() << endl;

    return 0;
}

Measured memory_bytes: 384
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	s = readline() |> chomp
	f = 0
	if length(s)==2
		if s[1]==s[2]
			f = 1
			println("1 2")
		end
	else
		for i in 1:length(s)-2
			if s[i]==s[i+1] || s[i]==s[i+2] || s[i+1]==s[i+2]
				f = 1
				println(i," ",i+2)
				break
			end
		end
	end
	if f==0
		println("-1 -1")
	end
end

main()

Measured memory_bytes: 124280
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
#define PI  3.14159265358979323846
#define M 1000000009
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
int main()
{
  int n,m;
  cin>>n>>m;
  if(n==m)
  {
      cout<<"Yes";
  }
  else
  {
      cout<<"No";
  }


}


Measured memory_bytes: 256