akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def combination(n, k):
    if n - k < k:
        return combination(n, n-k)
    
    if k == 0:
        return 1
    
    return combination(n-1, k-1) * n // k


def solve(N: int, A: int, B: int, v: "List[int]"):
    v.sort(reverse=True)
    d = dict()
    for value in v:
        if value not in d:
            d[value] = 1
        else:
            d[value] += 1
    
    average = sum(v[:A]) / A
    print(average)

    count = d[v[A-1]]
    fixed = v.index(v[A-1])
    
    if fixed > 0:
        print(combination(count, A - fixed))
        return

    if B - fixed < count:
        k2 = B - fixed
    else:
        k2 = count
    
    k1 = A - fixed

    ret = 0
    for k in range(k1, k2+1):
        ret += combination(count, k)
    print(ret)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define ll long long
#define foi(n) for(ll i=0;i<n;i++)
using namespace std;
int main(){
 
  ll n;
  cin>>n;
  ll a[n];
  foi(n)
  cin>>a[i];
  ll acc=accumulate(a,a+n,0LL);
  ll ans=0;
  ll b[n];
  b[0]=0;
  foi(n-1){
  	b[i+1]=b[i]+a[i];
  	b[i+1]%=1000000007;
  }
  foi(n){
  	ans+=(a[i]*(b[i]));
  	ans%=1000000007;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 6696
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    //          int[] split = Console.ReadLine().Split().Select(int.Parse).ToArray();

    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int answer = 0;
        for (int i = 0; i < N - 2; i++)
        {
            if (((p[i] < p[i + 1]) && (p[i + 1] < p[i + 2])) || ((p[i + 2] < p[i + 1]) && (p[i + 1] < p[i])))
            {
                answer++;
            }

        }
        Console.WriteLine(answer);
    }




}

public class Pairc
{
    public int a;
    public int b;
    public Pairc() { }
    public Pairc(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

}


Measured memory_bytes: 13396
import Control.Monad
import Control.Applicative
import Data.List

main :: IO ()
main = do
  input <- getLine
  -- let n = read input ::Int  
  let u = max 5 7
  let ans = show (snd (solve input))
  putStrLn ans

solve :: String -> (Int,Int)
solve s = if (length(s)==0) then (0,0) 
  else if (head(s)=='S') then (0,snd(solve(tail(s))))
  else ( 
    let aaa = solve(tail(s)) in  (fst(aaa)+1,(max (fst(aaa)+1) (snd aaa)))
  )








Measured memory_bytes: 3768
#include<stack>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
struct UnionFind {
    int n, cc, *u;
    UnionFind() : n(0), cc(0), u(NULL) {}
    UnionFind(int n_) : n(n_), cc(n_) {
	u = new int[n_];
	memset(u, -1, sizeof (int) * n);
    }
    UnionFind(const UnionFind &y) : n(y.n), cc(y.cc) {
	u = new int[y.n];
	memcpy(u, y.u, sizeof (int) * n);
    }
    ~UnionFind() {
	delete[] u; u = NULL;
	n = cc = 0;
    }
    friend void swap(UnionFind &x, UnionFind &y) {
	swap(x.n, y.n); swap(x.cc, y.cc); swap(x.u, y.u);
    }
    UnionFind& operator=(UnionFind y) { 
	swap(*this, y);
	return *this;
    }
    int root(int x) {
	int y = x, t;
	while (u[y] >= 0) y = u[y];
	while (x != y) { t = u[x]; u[x] = y; x = t; }
	return y;
    }
    bool link(int x, int y) {
	x = root(x); y = root(y);
	if (x == y) return false;
	if (u[y] < u[x]) swap(x, y);
	u[x] += u[y]; u[y] = x; cc--;
	return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -u[root(x)]; }
    int count() { return cc; }
};

int N, Q;

struct Edge {
    int x, y;
    LL c;
    int w;
    bool operator<(const Edge &o) const {
	return c < o.c;
    }
} E[200011];

void MAIN() {
    scanf("%d%d", &N, &Q);
    REP (i, Q) {
	scanf("%d%d%lld", &E[i].x, &E[i].y, &E[i].c);
    }

    sort(E, E+Q);
    UnionFind U(N);
    LL ans = 0;
    stack<Edge> s0, s1;
    LL cst = E[0].c;
    int idx = 0;
    while (1) {
	swap(s0, s1);
	while (idx < Q && E[idx].c == cst) {
	    s0.push(E[idx++]);
	}
	if (s0.empty()) break;
	while (!s0.empty()) {
	    Edge e = s0.top(); s0.pop();
	    e.w++;
	    if (!U.same(e.x, e.y)) {
		U.link(e.x, e.y);
//		eprintf("%d %d %lld %lld\n", e.x, e.y, e.c, cst);
		ans += cst;
		e.w = 0;
	    }
	    if (e.w <= 10) {
		e.x++;
		if (e.x >= N) e.x -= N;
		swap(e.x, e.y);
		e.c++;
		s1.push(e);
	    }
	}

	cst++;
    }

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

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 10752
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
const ll MAX_N = 3000;
/**/
int main() {
	// 入力
	ll A,B,C,D;cin>>A>>B>>C>>D;
    
	// 解法
	REP(i,1000){
		C -= B;
		if (C<=0){
			printf("Yes\n");
			break;
		}
		A -= D;
		if (A<=0){
			printf("No\n");
			break;
		}
	}
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();

			if (H == 0 && W == 0) {
				break;
			}

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (i == 0 || i == H - 1) {
						System.out.print("#");
					} else if (j == 0 || j == W - 1) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();

		}
	}
}



Measured memory_bytes: 32516
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
#include "math.h"
#include <string>
using namespace std;
int h[105][3];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i][1];
	}
	for (int i = 1; i <= n; i++) {
		cin >> h[i][2];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			h[i][0] += h[j][1];
		}
		for (int j = i; j <= n; j++) {
			h[i][0] += h[j][2];
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (ans < h[i][0])ans = h[i][0];
	}
	cout << ans << endl;
}

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




int main(){
    long long H,W;
    cin>>H>>W;
    long long count=0;
    
    count=(H*W+1)/2;
    
    

    if(H==1||W==1)count=1;
    cout<<count<<endl;        
    return 0;
    
}

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

int main(void){
  int a,b,c,d,e;
  for(int i=0;i<5;i++){
    cin >> a;
    if(a==0){
      cout << i+1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int n,i;
	scanf("%d",&n);
	
	int arr[n];
	for(i=0;i<n;i++) scanf("%d",&arr[i]);
	
	printf("%d",arr[n-1]);
	for(i=n-2;i>=0;i--) printf(" %d",arr[i]);
	
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
ll INF=1<<29;

//素数か否か判定
bool isprime(int n){
    for(int i=2; i*i<=n; i++){
        if(n%i==0) return false;
    }
    //n=1,2,3が上ループに入らないため別に判定
    return n!=1;
}

int main(){
	ios::sync_with_stdio(false);
	int Q,tmp=0;
	cin>>Q;
	int tab[100001],r[Q],l[Q];
	memset(tab,sizeof(tab),0);
	for(int i=1;i<=100000;i++){
		if(isprime(i) && isprime((i+1)/2)) tmp++;
		tab[i]=tmp;
	}
	for(int i=0;i<Q;i++) cin>>r[i]>>l[i];
	for(int i=0;i<Q;i++) cout<<tab[l[i]]-tab[r[i]-1]<<endl;
	return 0;
}

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

int main() {
  int X,Y,W,H,N,x,y,n;
  cin>>n;
  while(n--) {
    cin>>X>>Y>>W>>H;
    int mx = X+W,my = Y+H,ans = 0;
    cin>>N;
    for(int i=0; i<N; ++i) {
      cin>>x>>y;
      if(x <= mx && x >= X && y <= my && y >= Y) ans++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
card_list=[[],[],[],[]]
pattern = ["S", "H", "C", "D"]
n=int(input())
for i in range(n):
    card,num=input().split(" ")
    num=int(num)
    card_list[pattern.index(card)].append(num)

#print(card_list)
#print("ans")
#print()

for i,card in enumerate(card_list):
    missing=set(range(1,14))-set(card)
    #print(missing)
    for num in sorted(missing):
        print(pattern[i],num)



Measured memory_bytes: 5600
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{

    auto s = readln.chomp;
    auto t = readln.chomp;

    foreach (i; 0 .. s.length)
    {
        bool flag = true;
        foreach (k, c; s)
            flag &= (t[(k + i) % t.length] == c);
        if (flag)
        {
            "Yes".writeln;
            return;
        }
    }
    "No".writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int n;
    cin >> n;
    string s = "";
    while (n != 0) {
        Int quo = n / 26;
        Int rem = n % 26;
        if (rem == 0) {
            rem = 26;
            --quo;
        }
        s += char('a' + rem - 1);
        n = quo;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}



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

int main() {
    int a, b, ans = 0;
    cin >> a >> b;
    if(a >= 13) ans = b;
    else if(a >= 6) ans = b / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(raw_input()) + 1
A = [None] + map(int, raw_input().split())

ans = [0 for i in xrange(N)]

#print N, A

for i in range(N - 1, 0, -1):
    ind = i + i
    xor = A[i]
    while ind < N:
        xor ^= ans[ind]
        ind += i
    ans[i] = xor

print sum(ans)
for i in range(1, N):
    if ans[i]: print i,

Measured memory_bytes: 52524
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	long a, b, c;
	cin >> a >> b >> c;
	long ans;

	if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) ans = 0;
	else ans = min(a * b, min(b * c, c * a));

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

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

const int mod=1e9+7;
const int maxn=2e5+100;

int a[maxn];

int main()
{
    /*
    int n,k;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int tot=unique(a,a+n)-a;
    if(tot==n)
        printf("YES\n");
    else
        printf("NO\n");*/
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
        cout<<"x";
    return 0;
}
/*

*/


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

#pragma GCC diagnostic warning "-Wconversion"

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;

ll a[51], b[51];

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

        int n;
        cin >> n;

        fora(i, n)
        {
                cin >> a[i];
        }

        ll res = 0;

        while (true)
        {
                ll sum = 0;
                fora(i, n)
                {
                        b[i] = a[i] / n;

                        sum += b[i];
                        res += b[i];

                        a[i] %= n;
                }
                if (sum == 0)
                        break;

                fora(i, n)
                {
                        a[i] += sum - b[i];
                }
        }
        cout << res << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-12;
constexpr double pi=3.14159265358979323846264338;
//int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,a[100010],b[100010];
pair<P,int>c[100010];
P d[100010];
bool used[100010];
void dfs(int x){
    used[x]=true;
    if(!used[c[x].se])dfs(c[x].se);
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)c[i]={{b[i],a[i]},i};
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    rep(i,n){
        if(a[i]>b[i]){
            puts("No");
            return 0;
        }
    }
    rep(i,n-1){
        if(a[i+1]<=b[i]){
            puts("Yes");
            return 0;
        }
    }
    rep(i,n){
        c[i].se=i;
        swap(c[i].fi.fi,c[i].fi.se);
    }
    sort(c,c+n);
    dfs(0);
    rep(i,n){
        if(!used[i]){
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

ld pi = 3.14159265358979; 

int main(){
    ll a, b, h, m;
    cin>>a>>b>>h>>m;

    ld x = 30 * h + m * 0.5;
    ld y = 6 * m;
    ld flag = abs(x-y);
    if(flag > 180){
        flag  = 360 - flag;
    }
    ld z = flag * pi / 180;
    ld ans = a*a + b*b - 2*a*b*cos(z);
    cout<<setprecision(15)<<sqrt(ans)<<endl;
}

Measured memory_bytes: 4088
#include <stdio.h>

int main(void)
{
    int time, h, m, s;
    scanf("%d", &time);
    h = time / (60 * 60);
    m = (time - (time / (60 * 60)) * 60 * 60) / 60;
    s = time % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

long long a,b;
long long GCD(long long a,long long b)
{
    long long d;
    while(b != 0)
    {
        d = a%b;
        a = b;
        b = d;
    }
    return a;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    while(scanf("%lld%lld",&a,&b)!=EOF)
    {
        long long gcd = GCD(a,b);
        long long p = a/gcd,q = b/gcd;
        long long lcm = p*q*gcd;
        cout<<gcd<<" "<<lcm<<"\n";

    }
    return 0;
}

Measured memory_bytes: 3196
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
for i in range(k):
    tmp=t[i::k]
    l=len(tmp)
    dp=[[0 for i in range(3)] for j in range(l+1)]
    for j in range(1,l+1):
        dp[j][0] = max(dp[j-1][1]+r,dp[j-1][2]+r) if tmp[j-1] == 's' else max(dp[j-1][1],dp[j-1][2])
        dp[j][1] = max(dp[j-1][0]+s,dp[j-1][2]+s) if tmp[j-1] == 'p' else max(dp[j-1][0],dp[j-1][2])
        dp[j][2] = max(dp[j-1][0]+p,dp[j-1][1]+p) if tmp[j-1] == 'r' else max(dp[j-1][0],dp[j-1][1])
    ans+=max(dp[-1])
print(ans)


Measured memory_bytes: 17864
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,Max;
int b[100005],l[100005],r[100005];
int a[100005],sum;
bool cmp(int x,int y){
	int tx=x,ty=y;
	int vx=(Max-b[tx])*r[tx],vy=(Max-b[ty])*r[ty];
	int v2x=b[tx]*l[tx],v2y=b[ty]*l[ty];
	return (vx+v2x)>(vy+v2y);
}
bool ok(int t){
	int times=t/Max,rem=t%Max;
	if(times>=n)return 1;
	int tmp=0;
	for(int i=1;i<=times;i++){
		tmp+=b[a[i]]*l[a[i]]+(Max-b[a[i]])*r[a[i]];
	}
	int plus=0;
	for(int i=times+1;i<=n;i++){
		int pos=a[i];
		plus=max(plus,l[pos]*rem+(r[pos]-l[pos])*max(0ll,rem-b[pos]));
	}
	int best=plus+tmp;
	tmp+=b[a[times+1]]*l[a[times+1]]+(Max-b[a[times+1]])*r[a[times+1]];
	for(int i=1;i<=times;i++){
		int pos=a[i];
		best=max(best,tmp+
		l[pos]*rem+(r[pos]-l[pos])*max(0ll,rem-b[pos])
		-b[pos]*l[pos]-(Max-b[pos])*r[pos]);
	}
//	cerr<<t<<" "<<best<<" "<<sum<<endl;
	return best>=sum;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>Max;
	for(int i=1;i<=n;i++)cin>>b[i]>>l[i]>>r[i],sum+=b[i]*l[i];
	for(int i=1;i<=n;i++)a[i]=i;
	sort(a+1,a+n+1,cmp);
//	for(int i=1;i<=n;i++)cerr<<i<<"->"<<a[i]<<endl;
//	cerr<<"sum:"<<sum<<endl;int pos;for(int i=1;i<=n;i++)pos=a[i],cerr<<i<<" "<<l[pos]*b[pos]+r[pos]*(Max-b[pos])<<endl;
	int L=-1,R=Max*n+1;
	while(R-L>1){
		int mid=L+R>>1;
		if(ok(mid))R=mid;
		else L=mid;
	}
	cout<<R<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    string str;

    cin >> str;

    int i;
    int n = str.length();
    for(i = 0; i < n; i ++)
    {
    	if(i % 2 == 0 && str[i] != 'L')
    		continue;
    	else if(i % 2 == 1 && str[i] != 'R')
    		continue;
    	else
    		break;
    }
    if(i == n)
    	cout << "Yes" << endl;
    else
    	cout << "No" << endl;
}

Measured memory_bytes: 256
// AtCoder Grand Contest 019
// D - Shift and Flip

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 2000;

int N;
bitset<MAX_N + 1> A, B;

int solve() {
    if (B.none()) {
        if (A.none()) {
            return 0;
        }
        return -1;
    }

    int ret = 2 * N;
    bitset<MAX_N + 1> b = B, mask = B, remain;
    for (int d = 0; d <= N; d++) {
        vector<int> li(N), ri(N);

        li[N - 1] = N - 1;
        while (!mask[li[N - 1] % N]) {
            li[N - 1]++;
        }
        for (int i = N - 2; i >= 0; i--) {
            li[i] = mask[i] ? i : li[i + 1];
        }

        ri[0] = 0;
        while (!mask[(ri[0] + N) % N]) {
            ri[0]--;
        }
        for (int i = 1; i < N; i++) {
            ri[i] = mask[i] ? i : ri[i - 1];
        }

        vector<pii> xys;
        xys.push_back(pii(0, 0));
        remain = (A ^ b) & (~mask);
        for (int i = 0; i < N; i++) {
            if (remain[i]) {
                xys.push_back(pii(li[i] - i, i - ri[i]));
            }
        }
        sort(xys.begin(), xys.end());

        vector<int> y_max(xys.size() + 1);
        y_max[xys.size()] = 0;
        for (int i = xys.size() - 1; i >= 0; i--) {
            y_max[i] = max(y_max[i + 1], xys[i].second);
        }
        int k = N;
        for (int i = 0; i < (int)xys.size(); i++) {
            k = min(k, xys[i].first + y_max[i + 1]);
        }
        ret = min(ret, d + 2 * k + (int)(A ^ b).count());

        b <<= 1;
        b[0] = b[N];
        b[N] = 0;
        mask |= b;
    }

    return ret;
}

void rev(bitset<MAX_N + 1> &a) {
    string tmp = a.to_string().substr(MAX_N + 1 - N);
    reverse(tmp.begin(), tmp.end());
    a = bitset<MAX_N + 1>(tmp);
}

int main() {
    string tmp;
    cin >> tmp;
    A = bitset<MAX_N + 1>(tmp);
    cin >> tmp;
    B = bitset<MAX_N + 1>(tmp);
    N = tmp.size();

    int ans = solve();
    rev(A);
    rev(B);
    ans = min(ans, solve());

    cout << ans << endl;

    return 0;
}


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

using namespace std;

class UnionFind {
private:
	vector<int> v;
public:
	UnionFind(int n) {
		for (int i = 0; i < n; i++) v.emplace_back(-1);
	}
	int root(int x) {
		return v[x] < 0 ? x : root(v[x]);
	}
	void unite(int x, int y) {
		if (root(x) == root(y)) {
			return;
		}
		v[root(x)] = root(y);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	UnionFind uf(n);
	for (int i = 0; i < q; i++) {
		int com, x, y;
		cin >> com >> x >> y;
		if (!com) uf.unite(x, y);
		else cout << uf.same(x, y) << endl;
	}
	return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>


int main(int argc, const char * argv[]) {
    int i,j;
    for(i=1;i<10;i++){
        for(j=1;j<10;j++){
            printf("%dx%d=%d\n",i,j,i*j);
        }
    }
    
    return 0;
}


Measured memory_bytes: 2016
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	
	int W[N];
	for(int i=0; i<N; i++){
		cin >> W[i];
	}
	
	int T;
	int S1[N]={},S2[N]={},SA[N];
	for(int i=0; i<N-1; i++){
		T=i+1;
		for(int j=0;j<N;j++){
			if(j<=T-1)
				S1[i]+=W[j];
			if(j>=T)
				S2[i]+=W[j];
		}
		SA[i]=abs(S2[i]-S1[i]);
	}
	sort(SA,SA+N-1);
	
	cout<<SA[0]<<endl;
	
	
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    string S;
    getline(cin, S);

    for (int i = 0 ; i < S.size(); i++) {
        if (islower(S[i])) {
            S[i] = toupper(S[i]);
        }
        else {
            S[i] = tolower(S[i]);
        }
    }
    cout << S << '\n';

}



Measured memory_bytes: 3164
H,W = map(int,input().split())
S = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    S[i] = list(input())
for i in range(H):
    for j in range(W):
        if (S[i][j] == '.'):
            count = 0
            for a in range(-1,2):
                for b in range(-1,2):
                    if(0<=i+a<=H-1 and 0<=j+b<=W-1):
                        if(S[i+a][j+b] == '#'):
                            count += 1
            S[i][j] = count
    print(*S[i], sep='')


Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin >> str;
  int q,i;
  cin >> q;
  string s1,s2;
  int a,b;
  for(i=0;i<q;i++){
    //cout << str << endl;
    cin >> s1 >> a >> b;
    if(s1=="print"){
      cout << str.substr(a,b-a+1) << endl;
    }else if(s1=="reverse"){
      string s3=str.substr(a,b-a+1);
      reverse(s3.begin(),s3.end());
      str=str.substr(0,a)+s3+str.substr(b+1,str.size()-a-1);
    }else{
      cin >> s2;
      str=str.substr(0,a)+s2+str.substr(b+1,str.size()-a-1);
    }
  }
}


Measured memory_bytes: 3200
nums = int(input())
direct = list(input())
ary_w = [0 for i in range(nums)]
ary_e = [0 for i in range(nums)]
count_w = 0
count_e = 0
count = 0
result = 100000000

for i in range(nums):
    if direct[i] == "W":
        count_w += 1
    elif direct[i] == "E":
        count_e += 1

    ary_w[i] = count_w
    ary_e[i] = count_e

for i in range(nums):
    w = ary_w[i-1]
    e = ary_e[-1] - ary_e[i]
    if i == 0:
        w = 0
        e = ary_e[-1]
    count = w+e
    if count < result:
        result = count
print(result)

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int h, a;
  cin >> h >> a;
  cout << h / a + (h % a ? 1 : 0) << endl;
}


Measured memory_bytes: 256
function main(input) {
    var list = input[1].split("");
    var ans = 0;
    for(var i=0;i<list.length;i++){
        ans = Math.max(ans,check(list, i));
    }
    console.log(ans);
    
}
function check(list, idx){
    var a = {};
    var b = {};
    list.forEach((v,i)=>{
        if(i<=idx) a[v] = true;
        else b[v] = true;
    });
    var ans = 0;
    Object.keys(a).forEach(v=>{
        if(b[v]) ans++;
    });
    return ans;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 8136
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine().Split(' ').First());
        string[] s = new string[n];
        for (int i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }
        Array.Sort(s);
        foreach (string str in s)
        {
            Console.Write(str);
        }
    }
}

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

int main(void)
{
  int a,b,c;
  cin>>a>>b>>c;
  int d=100*a+10*b+c;
  if(d%4==0)
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int s[200][3],p,t[3][101]={0},n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&s[i][0],&s[i][1],&s[i][2]);
		for(j=0;j<3;j++)
			t[j][s[i][j]]++;
	}
	for(i=0;i<n;printf("%d\n",p),i++)
		for(j=p=0;j<3;j++)
			if(t[j][s[i][j]]==1)
				p+=s[i][j];
	return 0;
}

Measured memory_bytes: 600
let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p

let () = Scanf.scanf "%d %d" @@ fun a b ->
  Printf.printf "%d\n" @@
  lower_bound (-1) 1145141919 @@ fun i ->
    b <= (a - 1) * i + 1


Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  double max_conc = -1.0;
  ll total, sugar;
  REP(x,f/(100*a)+1){
    REP(y,f/(100*b)+1){
      if(100*a*x+100*b*y>f) continue;
      REP(z,f/c+1){
        if(100*a*x+100*b*y+c*z>f) continue;
        if((a*x+b*y)*e<c*z) continue;
        ll w = min((f-100*a*x-100*b*y-c*z)/d, ((a*x+b*y)*e-c*z)/d);
        double conc = (c*z+d*w)*1.0/(100*a*x+100*b*y+c*z+d*w);
        if(conc > max_conc){
          max_conc = conc;
          total = 100*a*x+100*b*y+c*z+d*w;
          sugar = c*z+d*w;
        }
      }
    }
  }
  cout << total << " " << sugar << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
using ull = unsigned long long;
const ll inf  = 1e18;
int main() {
	//cout<<inf;
	int n;
	cin >> n;
	vector<ull> a(n);
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	if(a[0] == 0)  {
		cout<<0;
		return 0;
	}
	ull mul = 1;
	for(int i=0;i<n;i++) {
		if(a[i] > inf/mul) {
			cout<<-1;
			return 0;
		}  else {
			mul*=a[i];
		}
		
	}
	cout<<mul;
}


Measured memory_bytes: 4056
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        Arrays.sort(h);

        int ans = 1000000000;
        for (int i = 0; i < N-K+1; i++) {
            ans = Math.min(ans, h[i+K-1] - h[i]);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 52496
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, double> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };



int main() {
	
	int a, b, h;
	cin >> a >> b >> h;

	cout << ((a + b) * h) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#Shiritori
def ABC_60_A():
    A,B,C = map(str, input().split())
    
    if A[len(A)-1] == B[0] and B[len(B)-1] == C[0]:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':

    ABC_60_A()

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int n;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++)cin>>p[i];
  int c=0;
  for(int i=1;i<n-1;i++){
    vector<pii>v;
    for(int j=-1;j<=1;j++)v.push_back({p[i+j],i+j});
    sort(rng(v));
    if(v[1].second==i)c++;
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int judge_prime(int n){
    int divcnt = 0;
    for(int i = 1; i <= n; i++){
        if(n % i == 0){
            divcnt ++;
        }
    }
    if(divcnt == 2){
        return 1;
    }
    return 0;
}


void print_array(int data[], int n){
    for(int i = 0; i < n; i++){
        printf("%d ", data[i]);
    }
    printf("\n");
}

int main(void){
    int n, i = 0, j = 1;
    scanf("%d", &n);
    int data[n];
    while(i < n){
        if(judge_prime(j * 5 + 1)){
            data[i] = j * 5 + 1;
            i++;
        }
        j++;
    }
    print_array(data, n);
    return 0;
}


Measured memory_bytes: 128
A,B = map(int,input().split())
X1 = int(A // 0.08)
X2 = int( (A+1) // 0.08)
array1 = []
for i in range(X1+1,X2):
  array1 += [i]
Y1 = int(B // 0.1)
Y2 = int( (B+1) // 0.1)
array2 =[]
for j in range(Y1+1,Y2):
  array2 += [j]
N1 = len(array1)
for t in range(N1):
  if array1[t] in array2:
    print(array1[t])
    exit()
print(-1)


Measured memory_bytes: 61980
N = int(input())
s = input()
R = s.count('R')
G = s.count('G')
B = s.count('B')

count = R*G*B
for d in range((N-1)//2):
    for i in range(N - (d+1)*2):
        if s[i] != s[i+d+1] and s[i] != s[i+2*(d+1)] and s[i+d+1] != s[i+2*(d+1)]:
            count -= 1
print(count)


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

using namespace std;

int main()
{
    string s;
    cin >> s;

    for (auto& c : s) {
        if (c == '1') {
            cout << '9';
        } else {
            cout << '1';
        }
    }
    cout << 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 ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  map<string, ll> mp;
  rep(i, n) {
    string s; cin >> s;
    sort(ALL(s));
    ++mp[s];
  }
  ll ans = 0;
  for(auto x : mp) ans += x.second*(x.second-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 11364
#include<stdio.h>
#include<string.h>
void search(char *p, char *t)
{
  int i;
  int M = strlen(p);
  int N = strlen(t);
   
  for (i = 0; i <= N - M; i++){
      int j;
      for (j = 0; j < M; j++){
        if (t[i+j] != p[j]) break;
      }
  
      if (j == M) printf("%d\n", i);
    }
}
   
int main()
{
  char t[1000];
  char p[1000];
  scanf("%s%s",t,p);
  search(p,t);
  return 0;
}

Measured memory_bytes: 548
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N; cin >> N;
    if (N <= 2) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll>L(N);
    rep(i, N) {
        cin >> L[i];
    }
    sort(L.begin(), L.end(),greater<int>());
    int ans = 0;
    for (int i = 0; i <=N-3; i++) {
        for (int j = i + 1; j <= N - 2; j++) {
            for (int k = j + 1; k <= N - 1; k++) {
                if (L[i] < L[j] + L[k]) {
                    ans++;
                    if (L[i] == L[j] || L[j] == L[k]) {
                        ans--;
                    }
                }
                
            }
        }
    }
    cout << ans << endl;
}



  

























Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define     fast                    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define     ll                      long long
#define     pb                      push_back
#define     M                       1000000007
using namespace std;
int main()
{
    ll n,x,y,sum=0;
    cin>>x>>y;
    sum = (x-1)*(y-1);
    cout<<sum<<endl;

}


Measured memory_bytes: 3560
#include<stdio.h>

long long int gcd(long long int a, long long int b){
	long long int r, t;
	if(a<b){
		t = a;
		a = b;
		b = t;
	}
	r = a % b;
	while(r!=0){
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int T, i;
long long int A, B, C, D, g, b;

int main(){
	scanf("%d", &T);
	for(i=0; i<T; i++){
		scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
		if(B>A){
			puts("No");
		}else if(B>D){
			puts("No");
		}else if(C>=B){
			puts("Yes");
		}else{
			g = gcd(B, D);
			b = B - g + A%g;
			if(b > C){
				puts("No");
			}else{
				puts("Yes");
			}
		}
	}
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int MAXN = 1 << 21;

int n,K;
int len[MAXN];
int top[MAXN];
int nxt[MAXN];
int sum[MAXN];
int f[21][MAXN];

char s[MAXN];

int getid(int d,int i,int j)
{
	return (i - (1 << d)) << (n - d + 1) | j;
}

int main()
{
	scanf("%d%d",&n,&K);
	for (int i = 0;i <= n;i++)
	{
		scanf("%s",s);
		for (int j = 0;j < (1 << i);j++)
			sum[j + (1 << i)] = s[j] - '0';
	}
	for (int i = (1 << n) - 1;i >= 1;i--)
		sum[i] += sum[i << 1] + sum[i << 1 | 1];
	for (int i = 1;i < (1 << (n + 1));i++)
	{
		for (int j = n;j >= 0;j--)
			if (i >> j & 1)
			{
				if (j)
				{
					len[i] = j;
					top[i] = (i >> (j - 1) & 1);
					nxt[i] = (i - (1 << j)) | (1 << (j - 1));
				}
				break;
			}
	}
	for (int d = n;d >= 0;d--)
		for (int i = (1 << (d + 1)) - 1;i >= (1 << d);i--)
		{
			f[d][getid(d,i,1)] = sum[i];
			for (int j = 2;j < (1 << (n - d + 1));j++)
			{
				f[d][getid(d,i,j)] = f[d + 1][getid(d + 1,i << 1 | top[j],nxt[j])];
				if (len[j] <= n - d - 1)
					f[d][getid(d,i,j)] += f[d + 1][getid(d + 1,i << 1 | (top[j] ^ 1),j)];
			}
		}
	int MX = -1,ans = 0;
	for (int i = 1;i < (1 << (n + 1));i++)
		if (f[0][i] >= K && len[i] > MX)
		{
			MX = len[i];
			ans = i;
		}
	for (int i = len[ans] - 1;i >= 0;i--)
		printf("%d",ans >> i & 1);
	printf("\n");
    return 0;
}

Measured memory_bytes: 206208
abcd = str(input())

a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

if a + b + c + d == 7:
    print("%s+%s+%s+%s=7" % (a, b, c, d))
elif a + b + c - d == 7:
    print("%s+%s+%s-%s=7" % (a, b, c, d))
elif a + b - c + d == 7:
    print("%s+%s-%s+%s=7" % (a, b, c, d))
elif a + b - c - d == 7:
    print("%s+%s-%s-%s=7" % (a, b, c, d))
elif a - b + c + d == 7:
    print("%s-%s+%s+%s=7" % (a, b, c, d))
elif a - b + c - d == 7:
    print("%s-%s+%s-%s=7" % (a, b, c, d))
elif a - b - c + d == 7:
    print("%s-%s-%s+%s=7" % (a, b, c, d))
elif a - b - c - d == 7:
    print("%s-%s-%s-%s=7" % (a, b, c, d))


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef unsigned long long state;

const int N = 50;

struct indirect {
  int *key;
  indirect(int *key) : key(key) { }
  bool operator () (int a, int b) const {
    return key[a] > key[b];
  }
};
int rec(int n, int ord[N], state D[N], state E[N],
        int k, state S, int acc, int &bound) {
  if (acc >= bound) return bound; // branch cut
  if (S == (1ull << n)-1) { // find solution
    bound = min(bound, acc);
    return acc;
  }
  if (k >= n) return bound; // could not cover...
  if ((S | E[ord[k]]) != (1ull << n)-1) return bound; // cannot cover when use all

  int u = ord[k]; // take ord[k] or not
  if ((S & D[u]) == D[u]) return rec(n, ord, D, E, k+1, S, acc, bound);
  else return min(rec(n, ord, D, E, k+1, S | D[u], acc+1, bound),
                  rec(n, ord, D, E, k+1, S       , acc  , bound));
}
int dominating_set(int g[N][N], int n) {
  state D[N];
  fill(D, D+n, 0);
  int C[N];
  for (int i = 0; i < n; ++i) {
    D[i] |= (1ull << i);
    C[i] = 1;
    for (int j = 0; j < n; ++j) {
      if (g[i][j]) {
        D[i] |= (1ull << j);
        ++C[i];
      }
    }
  }
  int ord[N]; // process from low degree's to high one
  for (int i = 0; i < n; ++i)
    ord[i] = i;
  sort(ord, ord+n, indirect(C));
  ord[n] = n;

  state E[N]; // make upper cover
  E[n] = 0;
  for (int i = n-1; i >= 0; --i)
    E[ord[i]] = E[ord[i+1]] | D[ord[i]];

  int bound = n;
  return rec(n, ord, D, E, 0, 0, 0, bound);
}

int main() {
  int g[N][N];
  int n, m;
  while(cin >> n >> m, n ||m) {
    memset(g, 0, sizeof(g));
    REP(i, m) {
      int x, y;
      cin >>  x >> y;
      g[x][y] = 1;
      g[y][x] = 1;
      
      // if (mp.count(x) == 0) mp[x] = sz++;
      // if (mp.count(y) == 0) mp[y] = sz++;
      // g[mp[x]][mp[y]] = 1;
      // g[mp[y]][mp[x]] = 1;
    }
    cout << dominating_set(g, n) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D, N;
  cin >> D >> N;
  
  int exp;
  
  if (D == 0) exp = 1;
  if (D == 1) exp = 100;
  if (D == 2) exp = 10000;
  
  if (N == 100) {
    cout << exp * 101 << endl;
  } else {
    cout << exp * N << endl;
  }
}




































Measured memory_bytes: 256
n = int(raw_input())
l = map(int, raw_input().split())
feven = False
nodd = 0
nfour = 0
for i in l:
    if i % 4 == 0:
        nfour += 1
    elif i % 2 == 0:
        feven = True
    else:
        nodd += 1
if (feven and nfour >= nodd) or (not feven and nfour >= nodd - 1):
    print 'Yes'
else:
    print 'No'


Measured memory_bytes: 11296