akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try {
            InputReader in;
            PrintWriter out;
            boolean useOutput = false;
            // if (System.getProperty("ONLINE_JUDGE") == null) useOutput = true;
            if (useOutput) {
                FileInputStream fin = new FileInputStream(new File("src/testdata.in"));
                in = new InputReader(fin);
                FileOutputStream fout = new FileOutputStream(new File("src/testData.out"));
                out = new PrintWriter(fout);
            } else {
                InputStream inputStream = System.in;
                in = new InputReader(inputStream);
                OutputStream outputStream = System.out;
                out = new PrintWriter(outputStream);
            }
            Solver solver = new Solver();
            solver.solve(in, out);
            out.close();
            // fin.close();
            // fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Solver
    {

        public void solve (InputReader cin, PrintWriter cout)
        {
            try {
                int n = cin.nextInt();
                if (n == 0) cout.println(0);
                else {
                    ArrayList<Integer> ret = new ArrayList<>();
                    ret.clear();
                    while (n != 0) {
                        if (n % -2 != 0) {
                            // cout.print(1);
                            ret.add(1);
                            n -= 1;
                        } else {
                            // cout.print(0);
                            ret.add(0);
                        }
                        n /= -2;
                    }
                    for (int i = ret.size() - 1; i >= 0; --i) {
                        cout.print(ret.get(i));
                    }
                }
            } catch (RuntimeException e) {
                e.printStackTrace();
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }
    }

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

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

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

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

        public long nextLong () {
            return Long.parseLong(next());
        }

        public double nextDouble () {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 21204
import math

N = int(input())

a = math.ceil(N ** (1/2))

for i in range(a):
  if int(N % (a-i)) == 0:
    aa = len(list(str(int(a-i))))
    bb = len(list(str(int(N // (a-i)))))
    break

print(max(aa,bb))


Measured memory_bytes: 3060
// 2012/07/09 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int w;
		cin >> w;

		if(w==-1)
			break;

		int bil;
		if(w<=10){
			bil = 1150;
		}
		else if(w<=20){
			bil = 1150+(w-10)*125;
		}
		else if(w<=30){
			bil = 1150+10*125+(w-20)*140;
		}
		else{
			bil = 1150+10*125+10*140+(w-30)*160;
		}

		cout << 4280-bil << endl;
	}

	return 0;
}

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

public class Main {
	public void maain(){

	}

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		//???????????£?¨?
		int building [][][] = new int [4][3][10];

		//?????????????????????????????\??????
    	for(int b_building = 0; b_building < 4; b_building++){
    		for(int stairs = 0; stairs < 3; stairs++){
    			for(int num = 0; num < 10; num++){
    				building[b_building][stairs][num] = 0;
    			}
    		}
    	}

		//1???????????\????????¢
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);

        //v??????????????\??????
        for(int set = 0;set < n; set++){
        	String[] input2 = br.readLine().split(" ");
        		int b = Integer.parseInt(input2[0]);
        		int f = Integer.parseInt(input2[1]);
        		int r = Integer.parseInt(input2[2]);
        		int v = Integer.parseInt(input2[3]);
        		building[b - 1][f - 1][r - 1] = building[b - 1][f - 1][r - 1] + v;
        }

		//?????¢?????¨?????????
    	for(int b_building = 0; b_building < 4; b_building++){
    		for(int stairs = 0; stairs < 3; stairs++){
    			for(int num = 0; num < 10; num++){
    				System.out.print(" ");
    				System.out.print(building[b_building][stairs][num]);
    			}
    			System.out.println();
    		}
    		if(b_building == 3){
    		}else{
    			System.out.println("####################");
    		}
    	}
	}
}

Measured memory_bytes: 24796
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<ll> sum[101010],rsum[101010];

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

	int N;
	cin >> N;
	vector<ll>s(N),rs(N);
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		rs[N - 1 - i] = s[i];
	}
	for (int k = 1; k < N;k++) {
		sum[k].pb(0);
		rsum[k].pb(0);
		for (int i = k; i < N; i+=k) {
			sum[k].pb(sum[k].back() + s[i]);
			rsum[k].pb(rsum[k].back() + rs[i]);
		}
	}

	ll ans = 0;
	for (int k = 1; k < N; k++) {
		for (int x = 1; (x-1)*k < N; x++) {
			ll A = N - 1 - (x - 1)*k;
			ll B = A - k;
			if (A > 0 && B > 0) {
				if (A%k != 0 || A > (x - 1)*k) {
					ans = max(ans, sum[k][x - 1] + rsum[k][x - 1]);
				}
			}
		}
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 34540
#include <bits/stdc++.h>
#define meow(args...) 0 //fprintf(stderr, args)
int w, h, k;
long long ans;
int gcd(int x, int y) {
	return y?gcd(y, x%y):x;
}
void solve() {
	meow("%d * %d\n", w, h);
	for(int d=0; d<h; ++d) {
		int coef=2*(1+!!d), a, kk=k+gcd(d, w);
		for(int c=1; c<w && c*d<=kk; ++c) {
			int a=(kk-c*d)/w;
			a=std::min(a, h-d-1);
			ans+=coef*a;
			meow("c=%d, d=%d: + %d*%d\n", c, d, a, coef);
			++a;
			if(a<h-d) {
				int b=a+d;
				meow("check (%d, %d, %d): + %d*%d\n", a, b, c, a*w+c*d<=kk+gcd(a, c)+gcd(b, w-c), coef);
				if(a*w+c*d<=kk+gcd(a, c)+gcd(b, w-c)) ans+=coef;
			}
		}
	}
}
int main() {
	scanf("%d%d%d", &w, &h, &k);
	k=2*k-2;
	solve();
	std::swap(w, h);
	solve();
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
bool sieve[100010];
int cu[100010];
int main(){
    int Q; cin >> Q;
    
    REP(i, 100000) sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for(int i=2; i*i<=100000; ++i){
        if(sieve[i]){
            for(int j=2; j*i<=100000; ++j){
                sieve[j*i]=false;
            }
        }
    }
    for(int i=3; i<=100000; i++){
        if(sieve[i]&&sieve[(i+1)/2]) cu[i] = cu[i-1]+1;
        else cu[i] = cu[i-1];
    }
    for(int i=0; i<Q; ++i){
        int l, r; cin >> l >> r;
        cout << cu[r] - cu[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 5888
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k, a, b;
    cin >> k >> a >> b;
    FOR(i, a, b){
        if(i % k == 0){
            cout << "OK" <<"\n";
            return 0;
        }
    }

    cout << "NG" <<"\n";
	return 0;
}

Measured memory_bytes: 3652
package main

import (
	"fmt"
)

func findSumOfDigits(n int) int {
	sum := 0
	for n > 0 {
		sum += n % 10
		n = n / 10
	}
	return sum
}

func main() {
	var n int
	fmt.Scan(&n)
	sum := findSumOfDigits(n)
	if n%sum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int h, w;
    cin >> h >> w;
    int h2 = h / 2, w2 = w / 2, h3 = h / 3, w3 = w / 3;
    int ans = min (h, w);
    if (h % 3 == 0 || w % 3 == 0) {
        ans = 0;
    } else {
        ans = min ({ans, (h3 + 1) * w - (h - h3 - 1) * w2,
                    (w3 + 1) * h - (w - w3 - 1) * h2});
        if (h % 2 == 0 && w % 2 == 0) {
            ans = min ({ans, h2 * (w - w3) - h * w3, w2 * (h - h3) - w * h3});
        } else if (h % 2 == 0) {
            ans = min (ans, abs (w3 * h - (w - w3) * h2));
        } else if (w % 2 == 0) {
            ans = min (ans, abs (h3 * w - (h - h3) * w2));
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<b; i++)
using namespace std;
typedef long long int ll;
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k,ans=0;
    cin>>n>>k;
    ll arr[n];
    rep(i,0,n) 
        cin>>arr[i];
    sort(arr, arr+n, greater<int>());
    if(k==0){
        rep(i,0,n)
            ans+=arr[i];
    } 
    else{
        rep(i,k,n){
            ans+=arr[i];
        }
    }
    //ans+=k;
    cout<<ans<<endl;   
return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            iOut = iA - iB * 2;
            if (iOut < 0) { iOut = 0; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=2e5+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
double f[N];
double sum[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    FOR(i,1,n){
        r(f[i]);
        sum[i]=sum[i-1]+(f[i]+1)/2;
    }
    double ans=0;
    FOR(i,1,n-m+1){
        ans=max(ans,sum[i+m-1]-sum[i-1]);
    }
    printf("%.8f\n",ans);
    return 0;
}


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

typedef long long ll;

int main() {
    const double pi = 3.141592653589793;
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double a, b;
    double c;
    double ans;
    a = 30*H;
    a += 0.5 * M;
    b = 6 * M;
    c = abs(a-b);
    if (c >= 180) {
        c = 360 - c;
    }

    
    if (c == 0) {
        cout << abs(A-B) << endl;
    }  else if (c == 90.0) {
        ans = sqrt(pow(A, 2)+pow(B, 2));
        printf("%.10f\n", ans);
    } else {
        ans = sqrt(pow(A, 2)+ pow(B, 2) - 2*A*B*cos(M_PI/180.0*c));
        printf("%.10f\n", ans);
    }
}


Measured memory_bytes: 4192
#include<bits/stdc++.h>
using namespace std;
#define fast                         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int                          long long int
#define double                       long double
#define ff                           first
#define ss                           second
#define pb                           push_back
#define eb                           emplace_back
#define all(x)                       (x).begin(), (x).end()
#define sz(x)                        ((int)(x).size())
#define len(x)                       ((int)(x).length())
#define pii                          pair<int,int>
#define vi                            vector<int>
#define vd                           vector<double>
#define vs                            vector<string>
#define mp                          map<int,int>
#define ms(x,y)                     memset(x,y,sizeof(x))
#define ump                         unordered_map<int,int>

#define lb                            lower_bound
#define ub                            upper_bound
#define nx                            cout<<"\n";
#define inf                           9223372036854775807
#define PI                            3.14159265

const int MOD = 1e9 + 7;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int add(int a, int b) {    return ((a % MOD) + (b % MOD)) % MOD;}

inline int multi(int a, int b) {   return ((a % MOD) * (b % MOD)) % MOD;}

inline int sub(int a, int b) {       a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;}

inline int power(int a, int b) {       a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;}  return res;}

bool isPrime(int  x) {      if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;}

int32_t main()
{
  fast ;


  string a, b; cin >> a >> b;
  int n = len(a), m = len(b);

  int dp[n + 1][m + 1];
  ms(dp, 0);

  for (int i = 1; i <= n; i++)
  {
    for (int j = 1; j <= m; j++)
    {
      if (a[i - 1] == b[j - 1])dp[i][j] = 1 + dp[i - 1][j - 1];
      else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
  }
  string res = "";
  int i = n, j = m;
  while (i > 0 && j > 0)
  {
    if (a[i - 1] == b[j - 1]) {
      res += a[i - 1];
      i--, j--;
    }
    else {
      if (dp[i - 1][j] > dp[i][j - 1])i--;
      else j--;
    }

  }
  reverse(all(res));
  cout << res;


}



Measured memory_bytes: 70656
X, Y, A, B, C = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p.sort()
q.sort()
r.sort(reverse=True)

p = p[-X:]
q = q[-Y:]

pi = 0
qi = 0

for rv in r :
  if 0 <= pi < X and 0 <= qi < Y :
    if p[pi] <= q[qi] and p[pi] < rv :
      p[pi] = rv
      pi += 1
      continue
    if q[qi] <= p[pi] and q[qi] < rv : 
      q[qi] = rv
      qi += 1
      continue
  
  if 0 <= pi < X and p[pi] < rv :
    p[pi] = rv
    pi += 1
    continue
    
  if 0 <= qi < Y and q[qi] < rv :
    q[qi] = rv
    qi += 1
    continue
    
print(sum(p[:X]) + sum(q[:Y]))


Measured memory_bytes: 104804
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	if(n==1) cout << a.at(0) << endl ;
	else{
		for(int i=n-1;i>=0;i-=2) cout << a.at(i) << " " ;
		for(int i=n%2;i<n;i+=2){
			cout << a.at(i) ;
			if(i==n-2) cout << endl ;
			else cout << " " ;
		}
	}
}


Measured memory_bytes: 3712
import heapq,collections
class Dijkstra():
    def __init__(self):
        self.e=collections.defaultdict(list)
    def add(self,u,v,d):
        self.e[u].append((v,d))
        self.e[v].append((u,d))
    def search(self,s):
        dist = [-1 for _ in range(n)]
        next_point = []
        heapq.heappush(next_point,(0,s))
        while next_point:
            cost,node = heapq.heappop(next_point)
            if dist[node] == -1:
                dist[node] = cost
                for u,d in self.e[node]:
                    if dist[u] == -1:
                        heapq.heappush(next_point,(cost+d,u))
        return dist

n,m,s,t = map(int,input().split())
graph_y = Dijkstra()
graph_s = Dijkstra()
for _ in range(m):
    u,v,a,b = map(int,input().split())
    graph_y.add(u-1,v-1,a)
    graph_s.add(u-1,v-1,b)
dist_y = graph_y.search(s-1)
dist_s = graph_s.search(t-1)
r = [0]*n
for i in range(n):
    r[-i-1] = max(r[-i],10**15-dist_y[-i-1]-dist_s[-i-1])
print(*r,sep='\n')

Measured memory_bytes: 125784
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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

ans = a[0]
for i in range(1, len(a)):
    ans = gcd(ans, a[i])
print(ans)

Measured memory_bytes: 62704
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main2():
    A,B,K=map(int,input().split())
    if A+K-1>=B-K+1:
        for i in range(A,B+1):
            print(i)
    else:
        for i in range(A,A+K):
            print(i)
        for i in range(B-K+1,B+1):
            print(i)

def main():
    numbers=[]
    a,b,k = map(int,input().split())
    numbers=np.arange(a,b+1)
    A=set(numbers[:k])
    B=set(numbers[-k:])
    answers = A|B
    
    for i in sorted(answers):
        print(i)

if __name__=="__main__":
    main2()

Measured memory_bytes: 27124
def main():
    n = int(input())
    p = list(map(float, input().split()))
    dp = [[0] * (n+1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        for j in range(i+1):
            dp[i+1][j+1] += dp[i][j] * p[i]
            dp[i+1][j] += dp[i][j] * (1-p[i])

    print(sum(dp[n][(n+1)//2:]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 263048
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int l = s.size();
bool ans = true;
  for(int i = 1;i < l;i++){
    for(int j = i-1;j >= 0;j--){
     // cout << j <<endl;
      if(s[i] == s[j]){
        ans = false;
        break;
      }
    }
  }
if(ans){
  cout<< "yes" <<endl;
}
else{
  cout << "no" <<endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;

int main(void)
{
    ll x, y, z;
    ll k10, k5, k1;
    ll N, Y;
    ll fomla1, fomla2;

    cin >> N >> Y;

    x = 0;
    y = Y / 5000;
    z = (Y % 5000) / 1000;

    while (y != -1)
    {
        k10 = x;
        k5 = y;
        k1 = z;

        while (k5 >= 0)
        {
            fomla1 = Y - (10000 * k10 + 5000 * k5 + 1000 * k1);
            fomla2 = N - (k10 + k5 + k1);

            if (fomla1 == 0 && fomla2 == 0)
            {
                cout << k10 << " " << k5 << " " << k1 << endl;
                return 0;
            }
            else
            {
                k5 -= 2;
                k10++;
            }
            //cout << k10 << " " << k5 << " " << k1 << endl;
        }
        y--;
        z += 5;
    }

    //cout << x << " " << y << " " << z << endl;
    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

ll modPow(ll a, ll n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  ll t = modPow(a, n / 2);
  return (t * t) % MOD;
}

int main(){
  ll N,ans=0,x=1;
  cin >> N;
  vec X(N),P(N);
  rep(i,N-1){
    x*=i+1;
    x%=MOD;
  }
  rep(i,N){
    if(i==0){
      P.at(i)=x;
    }else{
      P.at(i)=P.at(i-1)+x*modPow(i+1,MOD-2);
      P.at(i)%=MOD;
    }
  }
  cin >> X.at(0);
  rep(i,N-1){
    cin >> X.at(i+1);
    ans+=(X.at(i+1)-X.at(i))*P.at(i);
    ans%=MOD;
  }
  cout << ans << endl;
}

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

const ll MOD = 1000000007;
const ll MAX = 510000;
ll fac[1001000], inv[MAX], finv[MAX];

void preCOM() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 1001000; i++) {
    fac[i] = fac[i-1] * i % MOD;
    if (i < MAX) {
      inv[i] = MOD - (inv[MOD%i] * (MOD/i)) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
  }
}

ll COM (ll n, ll a) {
  if (n < a) return 0;
  if (n < 0 || a < 0) return 0;
  return fac[n] * (finv[a] * finv[n-a] % MOD) % MOD;
}

int main() {
  ll x, y;
  cin >> x >> y;
  if ((x+y)%3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  ll p = (x+y)/3;
  ll q = min(x-p, y-p);
  preCOM();
  cout << COM(p,q) << endl;
}

Measured memory_bytes: 19432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int k;
    string s;
    cin >> k >> s;
    int n = min(k, (int)s.size());
    rep(i, n)
    {
        cout << s.at(i);
    }
    if (k < s.size())
    {
        cout << "...";
    }

    cout << endl;

    return 0;
}

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

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if (s.size() > k) {
    cout << s.substr(0, k) << "..." << endl;
  }
  else {
    cout << s << endl;
  }  
}


Measured memory_bytes: 3576
#include<stdio.h>
#include<string.h>

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key%M;
}
int h2(int key){
  return 1+key%(M-1);
}

int find(char str[]){

  long long key,h,i;

  key=getKey(str);

  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }

  return 0;

}

int insert(char str[]){

  long long key,h,i=0;

  key=getKey(str);

  while(1){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
    i++;
  }
  return 0;

}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }

  return 0;
}




Measured memory_bytes: 15408
#include<stdio.h>

int main(void){
  int h, w;
  int i, j;
  int flg=0;
  char can[52][52];

  scanf("%d%d", &h, &w);

  for(i=0; i<52; i++){
    for(j=0; j<52; j++){
      can[i][j] = '.';
    }
  }

  for(i=1; i<h+1; i++){
    scanf("%s", can[i]);
  }

  for(i=1; i<h+1; i++){
    for(j=1; j<w+1; j++){
      if(can[i][j]=='#'){
        if(can[i-1][j]=='.' && can[i+1][j]=='.' && can[i][j-1]=='.' && can[i][j+1]=='.'){
          flg = 1;
        }
      }
    }
  }

  if(flg==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  // for(i=0; i<h; i++){
  //   printf("%s\n", can[i]);
  // }

  // i = j = 2;
  // printf("%dの%dは%cです", i, j, can[i][j]);

  return 0;
}


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

using namespace std;

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

  int a,b,c,ans = 0;
  cin >> a >> b >> c;
  
  if(b>=c) {
    ans += b+c;
    c = 0;
  } else {
    ans += 2*b;
    c -= b;
    if(a >= c) {
      ans += c;
      c = 0;
    } else {
      ans += a;
      c -= a;
    }
  }

  if(c) ans+=1;

  cout << ans << "\n";

}

Measured memory_bytes: 256
/**
 * File              : d.cpp
 * Author            : recurze
 * Date              : 21:35 18.01.2019
 * Last Modified Date: 21:45 18.01.2019
 */
#include <stdio.h>

void readInput();
void solve(int n, long long x);
void printAns();

int main() {
    int t = 1;
    //scanf("%d", &t);

    for (int tc = 1; tc <= t; ++tc) {
        readInput();
        printAns();
    }
}

const int N = 1010101;

int n = 0;
long long x = 0;
void readInput() {
    scanf("%d%lld", &n, &x);
    solve(n, x);
}

long long lengthOf(int n) {
    return (1LL << (n + 2)) - 3;
}

long long n_patty(int n) {
    return (1LL << (n + 1)) - 1;
}

long long ans = 0;
void solve(int n, long long x) {
    if (n == 0) {
        ans += (!!x);
        return;
    } if (x == 0) {
        return;
    }
    --x;

    long long y = lengthOf(n - 1);
    if (x <= y) {
        return solve(n - 1, x);
    }

    x -= y + 1;
    ans += n_patty(n - 1) + 1;
    solve(n - 1, x);
}

void printAns() {
    printf("%lld\n", ans);
}


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

int n;
ll dp[100001];
ll a[100000];

int main()
{
	cin >> n;
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	for(int i = 0;i<100001;i++)
	{
		dp[i] = 1e9;
	}
	for(int i = 0;i<n;i++)
	{
		ll *p = lower_bound(dp,dp+100001,a[i]);
		*p = min(a[i],*p);
	}
	int ans = lower_bound(dp,dp+100001,1e9)-dp;
	cout<<ans<<endl;
}


Measured memory_bytes: 4656
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
//26

int solve(int n){
	int ans = 0;
	while(n > 0){
		ans += n%10;
		n /= 10;
	}
	return ans;
}

signed main(){
	int n;
	scanf("%lld", &n);
	if(n%solve(n) == 0)printf("Yes\n");
	else printf("No\n");
	return 0;
}





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

int main(void){
 long long a,b,k;
 cin>>a>>b>>k;
  
 if(a<=k){
  k=k-a;
  a=0;
 }else{
  a=a-k;
  k=0;
  
 }
 if(b<=k){
  b=0; 
 }else{
  b=b-k; 
 }
  cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(T N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int A = inputVal<int>();
	const int B = inputVal<int>();

	const int sum = A + B;
	const int sub = A - B;
	const int mlt = A*B;

	outputVal(std::max(std::max(sum, sub), mlt));
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();


	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main()
{
	ll  i, j, k, l, m, sum, flag, N,  M, K, H, W, B,T;
	sum = 0;
	flag = 0;
	cin >> N ;
  if(N==1){
  output("Hello World");}
  else{
  cin>>B>>T;
    output(B+T);
  }
	return 0;

	
}













Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	int n;
	while ((n = in.nextInt()) != 0) {
	    int[][] map = new int[21][21];
	    for (int i = 0; i < n; i++) {
		map[in.nextInt()][in.nextInt()] = 1;
	    }
	    int m = in.nextInt();
	    int x = 10;
	    int y = 10;
	    int count = 0;
	    for (int i = 0; i < m; i++) {
		if (count != n) {
		    char c = in.next().charAt(0);
		    int l = in.nextInt();
		    int dx = 0;
		    int dy = 0;
		    if (c == 'N') {
			dy = 1;
		    } else if (c == 'E') {
			dx = 1;
		    } else if (c == 'S') {
			dy = -1;
		    } else if (c == 'W') {
			dx = -1;
		    }
		    for (int j = 0; j < l; j++) {
			count += map[x][y];
			map[x][y] = 0;
			x += dx;
			y += dy;
		    }
		    count += map[x][y];
		    map[x][y] = 0;
		} else {
		    in.next();
		    in.next();
		}
	    }
	    if (count == n) {
		System.out.println("Yes");
	    } else {
		System.out.println("No");
	    }
	}
    }
}

Measured memory_bytes: 43308
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

ll gcd(ll x, ll y) {
    if (y > x) {
        swap(x, y);
    }
    if (y == 1) {
        return 1;
    }
    if (y == 0) {
        return x;
    }
    if (x == y) {
        return x;
    }
    while(x > y) {
        x -= y;
    }
    return gcd(y, x);
}

ll lcm(ll x, ll y) {
    auto g = gcd(x,y);
    return x  * (y / g);
}
int run(istream& in, ostream& out) {
    ll A, B;
    in >> A >> B;
    ll ans = lcm(A, B);

    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
const long long INF = 1e12 + 1;
int main()
{
    long long n;
    cin >> n;
    long long ans = INF;
    for(long long i=2;i*i<=n;i++){
        if(n % i == 0){
            long long j = n/i;
            ans = min(ans,i + j -2);
        }
    }
    if(ans == INF)
        ans = n -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
 
int n;
 
int main()
{
int ans;
scanf("%d",&n);
if(n%2==0){ans=n*n/4;}
else{ans=n/2;ans=ans*(n+1)/2;}
  printf("%d\n",ans);
}

Measured memory_bytes: 128
/**
  @date Time-stamp: <2019-06-22 21:33:13 tagashira>
  @file b.cpp
  @title B - Bite Eating
  @brief https://atcoder.jp/contests/abc131/tasks/abc131_b
**/

#include <bits/stdc++.h>
using namespace std;

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

  vector<int> taste(N, 0);
  int sum       = 0;
  int index     = 0;
  int abs_value = 100000;
  for (int i = 0; i < N; i++) {
    taste[i] = L + i;
    sum += taste[i];
    if (abs_value > abs(taste[i])) {
      abs_value = abs(taste[i]);
      index     = i;
    }
  }

  cout << sum - taste[index] << endl;

  return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000000 + 7)

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 My_Combination(u32 n, u32 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

int main() {
  cout << setprecision(18);
  u32 N, K;
  string S;
  cin >> N >> K >> S;

  char prev = S[0];
  u32 l = 0, r = 0;
  bool flag = true;
  queue<pair<u32, u32>> Pos;
  u32 res = 0;
  for (u32 i = 1; i < N; ++i) {
    if (S[i] != prev) {
      if (flag) {
        l = i;
        flag = false;
      } else {
        r = i - 1;
        Pos.push(make_pair(l, r));
        flag = true;
      }
      prev = S[i];
    } else {
      ++res;
    }
  }
  if (!flag) Pos.push(make_pair(l, N - 1));
  u32 cnt = 0;
  while (!Pos.empty() && cnt < K) {
    pair<u32, u32> LR;
    ++cnt;
    LR = Pos.front();
    Pos.pop();
    res += 2;
    if (LR.first == 0 || LR.second == N - 1) --res;
  }
  cout << res << endl;

  return 0;
}


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

const int MAX = 1e5 + 10;

int main()
{
	string s; cin>>s; int k; cin>>k;
	int n=s.length();
	set<string> v;
	for(int i=1;i<=5;i++){
		if(i > s.size()) break;
		for(int j=i-1;j<n;j++){
			string t = s.substr(j-(i-1),i);
			v.insert(t);
		}
	}

	auto it = v.begin();

	advance(it, k-1);

	cout<<*it;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int n;
struct s{
	char n[20];
	int p;
	int id;
	bool operator <(const s &b)const{
		int l=max(strlen(n+1),strlen(b.n+1));
		for(int i=1;i<=l;i++){
			if(n[i]!=b.n[i]) return n[i]<b.n[i];
		}
		return p>b.p;
	}
}e[110];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s %d",e[i].n+1,&e[i].p);
		e[i].id=i;
	}
	sort(e+1,e+n+1);
	for(int i=1;i<=n;i++){
		printf("%d\n",e[i].id);
	}
}

Measured memory_bytes: 256
<?php
  while(true){
    $line = trim(fgets(STDIN));
    if($line == "0 0 0"){
      break;
    }
    $aline = explode(" ",$line);
    foreach($aline as $key => $val){
        $aline[$key] = (int)$val;
    }

    sort($aline);

    $maxLength = sqrt(pow($aline[0],2) + pow($aline[1],2));
    $num = fgets(STDIN);
    for($i = 0 ; $i < $num ; $i++ ){
        if($maxLength < fgets(STDIN) * 2){
          echo "OK" . "\n";
        }else{
          echo "NA" . "\n";
        }
    }
  }

Measured memory_bytes: 15468
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let order_p l =
  let rec doit = function
    | (_, _, []) -> true
    | ((x::xs' as xs), [], z::zs') when x < z -> doit (z::xs', [], zs') || doit (xs, [z], zs')
    | ((x::_ as xs), [], z::zs') when x >= z -> doit (xs, [z], zs')
    | ((x::_ as xs), y::ys', z::zs') when x >= z && y < z -> doit (xs, z::ys', zs')
    | (x::xs', (y::_ as ys), z::zs') when x < z && y >= z -> doit (z::xs', ys, zs')
    | ((x::xs' as xs), (y::ys' as ys), z::zs') when x < z && y < z -> doit (z::xs', ys, zs') || doit (xs, z::ys', zs')
    | _ -> false in
  doit ([List.hd l], [], List.tl l)

let () =
  let n = read_int () in
  let rec doit i =
    if i < n then begin
      let l = List.map int_of_string (split (read_line ()) ' ') in
      print_endline (if order_p l then "YES" else "NO");
      doit (i + 1)
    end in
  doit 0

Measured memory_bytes: 1884
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end
N, a_list = gets_n_and_i_list

a_list.sort!
total = 0
loop do
  if a_list.length == 1
    total = a_list[0]
    break
  end
  a_list = a_list.each_slice(2).map { |a, b| b ? a * b : a }
end

puts total > 10**18 ? -1 : total


Measured memory_bytes: 45252
n,k = gets.split.map(&:to_i)

i = 0
sum = 0.0
pre = n + 1
while pre != 1
    x = k.fdiv(2 ** i).ceil
    if pre >= x
        sum += (pre - x).fdiv(2 ** i)
        pre = x
    end
    i += 1
end

puts sum / n

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

using namespace std;

int main(){
    int n,sum = 1;
    cin >> n;
    string d;
    cin >> d;
    for(int i = 0 ; i < n - 1 ; i++){
        if(d[i] != d[i+1]){
            sum += 1;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define M 10000000
using namespace std;
vector<ll> prime;
bool status[10000001];
void siv()
{
    status[1] = 1;
    status[0] = 1;
    for (ll i = 2; i <= M; i++)
    {
        if (status[i] == false)
        {
            prime.push_back(i);
            for (ll j = 2 * i; j <= M; j = j + i)
            {
                status[j] = true;
            }
        }
    }
}
ll coutn(ll n)
{
    ll ans = 1;
    for (ll i = 0; i < prime.size(); i++)
    {
        ll p = prime[i];
        if (p * p * p > n)
            break;
        ll count = 1;
        while (n % p == 0)
        {
            n = n / p;
            count++;
        }
        ans *= count;
    }
    double sqprime = sqrt(n);
    ll flr = floor(sqprime);
    ll cel = ceil(sqprime);

    if (status[n] == false)
        ans *= 2;
    else if (status[cel] == false && cel == flr)
        ans *= 3;
    else if (n != 1)
        ans *= 4;
    return ans;
}
using namespace std;
int main()
{
    ll n, count, ans = 0;
    siv();
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        ans += i * coutn(i);
    }
    cout << ans;
}

Measured memory_bytes: 21196
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 100001
#define INF 1000000000
typedef vector<vector<int> > Graph;

typedef pair<int, int> P;
int V=MAX_V;
Graph G[MAX_V];
vector<int> ans(MAX_V);
int d[MAX_V];
void dijkstra(int s,const Graph &G){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0, s));
    while (!que.empty()){
        P p = que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for (int i=0;i<G[v].size();i++) {
            int to=G[v][i];
            if (d[to]>d[v]+1){
                d[to]=d[v]+1;
                ans[to]=v+1;
                que.push(P(d[to],to));
            }
        }
    }
}

int main(){
    int n,m;cin>>n>>m;
    Graph G(n);
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dijkstra(0,G);
    int flag=1;
    for(int i=1;i<n;i++){
        if(ans[i]==INF) flag=0;
    }
    if(flag){
        cout<<"Yes"<<endl;
        for(int i=1;i<n;i++) cout<<ans[i]<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 13440
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int N;
    cin >> N;
    vector<string> titles(N);
    vector<int> times(N);
    rep(i, 0, N)
    {
        cin >> titles[i];
        cin >> times[i];
    }
    string X;
    cin >> X;

    int sum = 0;
    int status = false;
    rep(i, 0, N)
    {
        if (status)
            sum += times[i];
        if (titles[i]==X)
            status = true;
    }
    cout << sum << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int ma=0;
    ma=max(a+b,max(a*b,a-b));
    cout << ma << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;

int find(int x, vector<int> &p) {
	if (p[x] == x)return x;
	return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
	x = find(x, p);
	y = find(y, p);
	p[x] = y;
}

int same(int x, int y, vector<int> p) {
	if (find(x, p) == find(y, p))return 1;
	return 0;
}

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

	if (N < 1000) {
		printf("ABC");
	}
	else {
		printf("ABD");
	}


	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256