akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    int n = s.size();
    vector<int> next_left(n);

    for(int i = n - 1; i >= 0; --i) {
        if(s[i] == 'L')
            next_left[i] = i;
        else
            next_left[i] = next_left[i + 1];
    }
    // copy(next_left.begin(), next_left.end(), ostream_iterator<int>(cout, " "));
    // cout << endl;

    vector<int> prev_right(n);

    for(int i = 0; i < n; ++i) {
        if(s[i] == 'R')
            prev_right[i] = i;
        else
            prev_right[i] = prev_right[i - 1];
    }
    // copy(prev_right.begin(), prev_right.end(), ostream_iterator<int>(cout, " "));
    // cout << endl;

    vector<int> out(n);

    for(int i = 0; i < n; ++i) {
        if(s[i] == 'R') {
            int left = next_left[i];
            int tail = left - i;
            if(tail % 2 == 0)
                ++out[left];
            else
                ++out[left - 1];
        } else {
            int right = prev_right[i];
            int tail = i - right;
            if(tail % 2 == 0)
                ++out[right];
            else
                ++out[right + 1];
        }
    }

    copy(out.begin(), out.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    return 0;
}


Measured memory_bytes: 1792
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n = int(ri())
if n%1000 == 0:
    print(0)
else:
    print(1000 - n%1000)

Measured memory_bytes: 63036
#include <stdio.h>
#define MAX 500000
int H,A[MAX];

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
void maxHeapify(int i){
  int l=left(i);
  int r=right(i);
  int largest,tmp;
  if(l<=H && A[l]>A[i])largest = l;
  else largest = i;

  if(r<=H && A[r]>A[largest])largest = r;

  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);

  for(i=H/2;i>=1;i--)maxHeapify(i);

  for(i=1;i<=H;i++)printf(" %d",A[i]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    int h;
    for (int i = 0; i < n; i++){
        cin >> h;
        if (h >= k) ans++;
    }
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3612
#include<stdio.h>
#define MAX 2000000
int H,A[MAX+1];
void maxHeapify(int A[],int i){
  int l,r,largest,tmp;
  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i]) largest = l;
  else largest = i;
  if( r<= H && A[r]>A[largest]) largest = r;
  if( largest!=i ){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}
void buildMaxHeap(int A[]){
  int i;
  for(i=H/2;i>=1;i--){
    maxHeapify(A,i);
  }
}
int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap(A);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3668
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<int> p(n), q(n), cmp(n);
	for (int i = 0; i < n; ++i) cin >> p[i];
	for (int i = 0; i < n; ++i) cin >> q[i];
	for (int i = 0; i < n; ++i) cmp[i] = i + 1;
	int a, b;
	int now = 0;
	do {
		if (cmp == p) a = now;
		if (cmp == q) b = now;
		++now;
	} while (next_permutation(cmp.begin(), cmp.end()));
	cout << abs(a - b) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

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

        int key1 = 0;
        int key2 = 0;
        int val1 = 0;
        int val2 = 0;

        for (int i = 0; i < n; i++) {
            int b = sc.nextInt();
            a[i] = b;
            if (b > val1) {
                val1 = b;
                key1 = i;
            } else if (b > val2) {
                val2 = b;
                key2 = i;
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == val1) {
                System.out.println(val2);
            } else {
                System.out.println(val1);
            }
        }

    }
}


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

int main(){
    int n,k;
    cin>>n>>k;
    int ans=k;
    rep(i,n-1){
        ans*=k-1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=200010;
 
int n,c[maxn],num[maxn];
bool vis[maxn];
char s[maxn];
vector<int>v[30];
void modify(int x,int k){for(int i=x;i<=n;i+=lowbit(i))c[i]+=k;}
int query(int x){int ans=0;for(int i=x;i>=1;i-=lowbit(i))ans+=c[i];return ans;}
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++)num[s[i]-'a']++,v[s[i]-'a'].push_back(i);
    int ok=0;
    for(int i=0;i<26;i++){
        if(num[i]%2)ok++;
    }
    if(ok>1){printf("-1");return 0;}
    for(int i=1;i<=n+1;i++)modify(i,1);
    ll ans=0;
    for(int i=1;i<=n;i++)if(!vis[i]){
        int c=s[i]-'a';
        int x=v[c][v[c].size()-1];
        if(i==x){
            ans+=(query(n)-query(i))/2;
        }
        else{
            ans+=(query(n)-query(x));
        }
        modify(i,-1);modify(x,-1);
        vis[i]=vis[x]=1;
        v[c].erase(v[c].end()-1);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P,P> P2;
const int INF = 1 << 30;
const double EPS = 1E-9;

int c[1000000];
int co[1000000];
int po[300];

int main(){
	int n;
	fill(c, c + 1000000, INF);
	fill(co, co + 1000000, INF);
	c[0] = co[0] = 0;
	for(int i = 0; i < 300; i++){
		po[i] = i * (i + 1) * (i + 2) / 6;
	}
	for(int i = 0; i < 1000000; i++){
		for(int j = 1; j < 300; j++){
			if(i + po[j] >= 1000000) break;
			if(c[i + po[j]] > c[i] + 1){
				c[i+po[j]] = c[i] + 1;
			}
		}
	}
	for(int i = 0; i < 1000000; i++){
		for(int j = 1; j < 300; j++){
			if(!(po[j] & 1)) continue;
			if(i + po[j] >= 1000000) break;
			if(co[i+po[j]] > co[i] + 1){
				co[i+po[j]] = co[i] + 1;
			}
		}
	}
	while(cin >> n && n){
		cout << c[n] << " " << co[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 8564
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//var min, min2, count: Int!
//for i in 1...10 {
//    let x = Int(readLine()!)!
//    if i == 1 {
//        min = x
//        count = 1
//    } else if x < min {
//        min2 = min
//        min = x
//        count = 1
//    } else if x == min && count == 1 {
//        min2 = x
//        count = 2
//    }
//}
//print(min2)

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (H, W) = (input[0], input[1])
var map = [[String]]()
for _ in 0..<H {
    map += [readLine()!.toArray()]
}
for i in 0..<H {
    for j in 0..<W {
        if map[i][j] == "." {
            var bomb = 0
            for h in -1...1 {
                for w in -1...1 {
                    if i+h>=0 && i+h<H && j+w>=0 && j+w<W {
                        if map[i+h][j+w] == "#" {
                            bomb += 1
                        }
                    }
                }
            }
            map[i][j] = String(bomb)
        }
    }
}
for i in 0..<H {
    print(map[i].joinWithSeparator(""))
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

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

    string ans;

    if ( R < 1200 ) { ans = "ABC"; }
    else if ( R < 2800 ) { ans = "ARC"; }
    else { ans = "AGC"; }

    cout << ans << endl;

    return 0;
}

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

void simulate(string s, int l){
  string L, S;
  set<string> M;
  map<string, int> I;
  int b = 1;
  while( s.size() < l ) s = "0" + s;
  for ( int i = 0; i < l-1; i++ ) b *= 10;
  
  for ( int cur = 0; ; cur++ ){
    M.insert(s);
    I[s] = cur;
    L = S = s;
    sort(L.begin(), L.end(), greater<char>());
    sort(S.begin(), S.end());
    int x = atoi(L.c_str()) - atoi(S.c_str());
    for ( int i = 0, p = b; i < l; i++, p /= 10 ){
      s[i] = '0' + x/p;
      x %= p;
    }
    if ( M.find(s) != M.end() ) {
      cout << I[s] << " " << atoi(s.c_str()) << " " << cur - I[s]+1<< endl;
      break;
    }
  }
}

main(){
  string s;
  int l;
  while(1){
    cin >> s >> l;
    if ( s == "0" && l == 0 ) break;
    simulate(s, l);
  }
}

Measured memory_bytes: 1256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = [0] * N
for i in range(N):
    ansi = T - H[i] * 0.006
    ans[i] = abs(A - ansi)

import numpy as np
print(np.argmin(ans) + 1)

Measured memory_bytes: 12592
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var nums = System.Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = nums[0];
        var k = nums[1];

        var p = System.Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var max = double.MinValue;

        double[] ruiseki = new double[n];

        ruiseki[0] = kitaichi(p[0]);

        for(int i = 1; i < n; i++)
        {
            ruiseki[i] = kitaichi(p[i]) + ruiseki[i - 1];
        }

        for(int i = 0; i <= n - k; i++)
        {
            var sum = ruiseki[i + k - 1];
            if(i != 0)
            {
                sum -= ruiseki[i - 1];
            }
            max = max > sum ? max : sum;
        }

        System.Console.WriteLine(max);
    }

    public static double kitaichi(int kitai)
    {
        if(kitai % 2 == 0)
        {
            return (1 + kitai) / 2.0;
        }
        else
        {
            return (kitai / 2) + 1;
        }
    }

}



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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

ll f(ll n) {
  ll res = 0;
  while (n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

double g(ll n) {
  return (double)(n)/f(n);
}

int main() {
  vector<ll> res;
  ll base = 1;

  for (int i = 0; i < 15; ++i) {
    for (int j = 1; j < 150; ++j) {
      res.push_back(base * (j+1) - 1);
    }
    base *= 10;
  }
  sort(res.begin(), res.end());
  res.erase(unique(res.begin(), res.end()), res.end());

  for (long long i = 0; i < res.size(); ++i) {
    for (long long j = i+1; j < res.size(); ++j) {
      if (g(res[i]) > g(res[j])) {
        res.erase(res.begin() + i--);
        break;
      }
    }
  }

  long long K;
  cin >> K;

  for (long long i = 0; i < K; ++i) {
    cout << res[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int  i,n,m;
  long long count=1;
  scanf("%d%d",&n,&m);
  if(n==m){
    for(i=1;i<=n;i++){
      count*=(long long)i;
      count%=1000000007;
      if(count==0)
        count=1000000007;
    }
    count*=count;
    count*=2;
    count%=1000000007;
  }
  else if(abs(n-m)==1){
    for(i=n;i>0;i--){
      count*=(long long)i;
      count%=1000000007;
      if(count==0)
        count=1000000007;
    }
    for(i=m;i>0;i--){
      count*=(long long)i;
      count%=1000000007;
      if(count==0)
        count=1000000007;
    }
  }
  else
    count=0;
  printf("%lld\n",count);
  return 0;
}


Measured memory_bytes: 1700
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            long X = in.Long();

            int max = 1000;
            int min = -max;
            for (long n = min; n < max; n++) {
                long A = (long) Math.pow(n, 5);
                for (long m = min; m < max; m++) {
                    long B = (long) Math.pow(m, 5);
                    if (A - B == X) {
                        out.println(n + " " + m);
                        return;
                    }
                }
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



Measured memory_bytes: 36944
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.println(a-b+1);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef long long int ll;
int n;
ll k,a[N],e[N][2],d[N];
int main(){
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    ll ans=0;
    for(ll i=0;i<63;i++){
        ll tmp=0;
        for(int j=0;j<n;j++){
            if((a[j]>>i)&1) tmp++;
        }
        if(i) {e[i][0]=max(e[i-1][0],e[i-1][1])+(ll)pow(2,i)*tmp;
            e[i][1]=max(e[i-1][0],e[i-1][1])+(ll)pow(2,i)*(ll)(n-tmp);
        }
        else {
            e[i][0]=tmp;
            e[i][1]=(n-tmp);
        }
        if(i){
            d[i] = max(d[i-1]+(ll)pow(2,i)*tmp,d[i]);
            if((k>>i)&1){
                d[i] = max(d[i],max(e[i-1][0],e[i-1][1])+(ll)pow(2,i)*tmp);
                d[i] = max(d[i-1]+(ll)pow(2,i)*(n-tmp),d[i]);
            }
            ans=max(ans,d[i]);
        }
        else {
            d[0]=tmp;
            if(k&1) d[0]=max(d[0],n-tmp);
            ans=max(ans,d[0]);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define MAX 10000000
using namespace std;

typedef pair<int,int> P;

struct edge{
  int cost,to; edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};

int n,k;
long long costed[111];
vector< vector<edge> > info;

void init(){
  for(int i=0;i<111;i++) costed[i] = MAX;
}

void information(){
  int c,d,e;
  cin >> c >> d >> e;
  info[c].push_back(edge(d,e));
  info[d].push_back(edge(c,e));
}

int Dijkstra(){
  init();
  int number,a,b;
  priority_queue<P,vector<P>,greater<P> > que;
  cin >> number;
  if(number == 1){
    information();
    return -10;
  } else {
    cin >> a >> b;
    que.push(P(0,a));
    costed[a] = 0;
    while(!que.empty()){
      P p = que.top(); que.pop();
      int now = p.second,c = p.first;
      if(now == b) return c;
      for(int i=0;i<info[now].size();i++){
	edge e = info[now][i];
	if(e.cost + c < costed[e.to]){
	  que.push(P(e.cost + c,e.to));
	  costed[e.to] = e.cost + c;
	}
      }
    }
    return -1;
  }
}


int main(){
  while(cin >> n >> k,n||k){
    init();
    info.resize(n+1);
    while(k--){
      int d = Dijkstra();
      if(d == -10) continue;
      else cout << d << endl;
    }
    info.clear();
  }
}

Measured memory_bytes: 1236
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int dp[100010];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, 100010)dp[i] = INF;
	dp[0] = 0;
	rep(i, n-1) {
		chmin(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
		if(i < n - 2)chmin(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
P A[100],j=sqrt(-1);
double a,b,d;
int n;
int f(int m,P p,P p1){
	int i,s1=2,s2=2;
	P p3=polar(1.0,b+d)+p,p4=polar(1.0,b-d)+p,q;
	for(i=0;i<n;i++){
		q=A[i];
		if(q==p||q==p1)continue;
		if(abs(q-p3)-1<1e-6)s1++;
		if(abs(q-p4)-1<1e-6)s2++;
	}
	if(m<s1)m=s1;
	if(m<s2)m=s2;
	return m;
}
int main(){
	int m,i,i1;
	char c;
	while(cin>>n,n!=0){
		for(i=0;i<n;i++){
			cin>>a>>c>>b;A[i]=P(a,b);
		}
		m=1;
		for(i=0;i<n;i++){
			P p=A[i],q;
			for(i1=i+1;i1<n;i1++){
				q=A[i1];a=abs(q-p);b=arg(q-p);d=acos(a/2);
				if(a<=2)m=f(m,p,q);
			}
		}
		cout<<m<<endl;
	}
}

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

signed main(){
	string S;
	cin>>S;
	sort(S.begin(),S.end());
	if(S[0]==S[1]&&S[2]==S[3]&&S[1]!=S[2]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)


n,m=map(int,input().split())

p=[[] for _ in range(n)]

for _ in range(m):
    x,y=map(int,input().split())
    p[x-1].append(y-1)

f=[-1 for _ in range(n)]

def calc(x):
    if f[x]!=-1:
        return f[x]
    if len(p[x])==0:
        f[x]=0
        return 0
    f[x]=max([calc(i) for i in p[x]])+1
    return f[x]

m=0
for i in range(n):
    if f[i]!=-1:
        continue
    m=max(m,calc(i))
print(m)


Measured memory_bytes: 115480
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    ll x, y, z; cin >> x >> y >> z;
    x -= z;
    cout << x / (y+z) << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    long double a,b;
    cin>>a>>b;
    cout<<(ll)(a*b);
    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	string s;
	cin >> s;
	int n = s.size();
	if (s[0] == s[n - 1]) {
		cout << (n % 2 ? "Second" : "First") << endl;
	}
	else {
		cout << (n % 2 ? "First" : "Second") << endl;
	}
}

Measured memory_bytes: 512
my ($n,$m,$q) = split(/\s+/,<STDIN>);

my @d = ();
for(my $i=0;$i<$q;$i++){
  my @du = split(/\s+/,<STDIN>);
  push(@d,\@du);
}

my $mx = 0;

my @st = ();
for(my $i=0;$i<$n;$i++){
  $st[$i] = 0;
}

while(1){
  #print ( join(":",@st) . "\n");
  my $sc = 0;
  for(my $k=0;$k<$q;$k++){
    if( $st[$d[$k]->[1]-1] - $st[$d[$k]->[0]-1] == $d[$k]->[2] ){
      $sc += $d[$k]->[3];
    }
  }
  
  if( $sc > $mx ){ $mx = $sc; }
  last unless &cup;
  
}
print "$mx\n";
exit(0);


for(my $i=1;$i<1024;$i++){
  my $sc = 0;
  my @aa = ();
  
  my $j = 1;
  for(my $k=0;$k<10;$k++){
    if( $j & $i ){
      push(@aa,$k);
    }
    $j += $j;
  }
  next unless $#aa == $n - 1;
  print (join(':',@aa) . "\n");
  
  for(my $k=0;$k<$q;$k++){
    if( $aa[$d[$k]->[1]-1] - $aa[$d[$k]->[0]-1] == $d[$k]->[2] ){
      $sc += $d[$k]->[3];
    }
  }
  
  if( $sc > $mx ){ $mx = $sc; }
}
print "$mx\n";

sub cup {
  my $i = $n - 1;
  my $c = 1;
  while( $i>=0 and $c > 0 ){
    $st[$i] += $c;
    $c = 0;
    if( $st[$i]>$m - 1 ){
      $c = 1;
      $st[$i] = $st[$i-1];
      $i--;
    }
  }
  return 0 if( $c>0 );
  #print ( "i=$i  " . join(',',@st) .  "\n");
  for(my $j=$i+1;$j<$n;$j++){
    $st[$j] = $st[$i];
  }
  #print ( "i=$i  " . join(',',@st) .  "\n");
  return 1;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A>B) swap(A,B);
  if(B>C) swap(B,C);
  if(A>B) swap(A,B);
  int count=0;
  count+=C-B;
  A+=C-B;
  if((C-A)%2==0){
    count+=(C-A)/2;
  }else{
    count++;
    count+=(C-A+1)/2;
  }
  cout << count << endl;
  return 0;
}

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

#define N 100
#define MAX (1<<21)

typedef pair<double,int> PI;
#define MP make_pair

double d[N];
double cost[N][N];
int hantei[N];

void prim(int n){
  priority_queue<PI,vector<PI>,greater<PI> > Q;
  for(int i=0;i<n;i++){d[i] = MAX;hantei[i]=0;}
  Q.push(MP(0,0) );
  d[0]=0;
  while(!Q.empty()){
    int now = Q.top().second;
    Q.pop();
    hantei[now]=1;

    for(int i=0;i<n;i++){
      if (i == now || hantei[i]==1)continue;
      if (cost[now][i] < d[i]){
	//cout << now<<" to " << i <<" "<<cost[now][i] << endl;
	d[i]=cost[now][i];
	Q.push(make_pair(cost[now][i],i));
      }
    }  
  }//while end
  



}




int main(){
  while(1){
    int n;
    double in[100][4];
    cin >> n;
    if (n ==0)break;
    for(int i=0;i<n;i++)
      cin >> in[i][0] >> in[i][1] >> in[i][2] >> in[i][3];
    
    
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if (i == j){cost[i][j]=MAX;continue;}
	double distance = sqrt( pow(in[i][0]-in[j][0],2)+pow(in[i][1]-in[j][1],2)+pow(in[i][2]-in[j][2],2));
	//cout << distance << endl;
	if ( distance > in[i][3]+in[j][3])cost[i][j] = distance - (in[i][3]+in[j][3]);
	else if (distance <= in[i][3]+in[j][3])cost[i][j] = 0;
      }
    }



    
    prim(n);
    double total = 0;
    for(int i=0;i<n;i++){total+= d[i];}
    printf("%.3lf\n",total);


  }
  return 0;
}





/*

0-1  0 
0-3  69.255
2-3  0
4-3  4.579

*/

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

using namespace std;
using ll = long long;


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    double n;
    cin >> n;
    double a;
    a = ceil((n) / 2.0) / (n);
    cout << setprecision(10) << fixed << a;
    return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  if(A!=1 && B!=1){
    cout << 1 << endl;
  }
  else if(A!=2 && B!=2){
    cout << 2 << endl;
  }
  else{
    cout << 3 << endl;
  }
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=1000;
int n,a,b,x;
string s;
vector<int>v;
bool vis[N];
int main(){
	scanf("%d%d%d",&n,&a,&b);
	for(int i =0;i<n;i++){
		scanf("%d",&x);
		v.push_back(x);
	}
	sort(all(v));
	int cnt=0;
	for(int i =0;i<v.size();i++){
		if(v[i]<=a){
			for(int j=i+1;j<v.size();j++){
				if(j!=i&&v[j]>=a+1&&v[j]<=b){
					for(int e=j+1;e<v.size();e++){
						if(e!=j&&e!=i&&v[e]>=b+1&&!vis[i]&&!vis[j]&&!vis[e]){
							cnt++;
							vis[i]=vis[j]=vis[e]=true;
						}
					}
				}
			}
		}
	}
	printf("%d\n",cnt );

	return 0;
}

Measured memory_bytes: 256
itl = lambda: list(map(int, input().strip().split()))


def solve():
    L = 10 ** 18
    N = int(input())
    A = itl()
    for i in range(N):
        if A[i] == 0:
            return 0
            
    curr = 1
    for i in range(N):
        curr *= A[i]
        if curr > L:
            return -1
    return curr


if __name__ == '__main__':
    print(solve())
    
         

Measured memory_bytes: 21616
#include<stdio.h>

int main(){
  int hisi = 0, quat = 0, a, b, c;
  while(scanf("%d,%d,%d", &a, &b, &c) != EOF){
    if(a * a + b * b == c * c)quat++;
    if(a == b)hisi++;
  }
  printf("%d\n%d\n", quat, hisi);
  return 0;
}

Measured memory_bytes: 596
#!/usr/bin/python3                                                                                                                                                                                          

import itertools

def all_comb(n):
    comb = []
    for i in range(0, n+1):
        comb.extend(list(itertools.combinations(range(n), i)))
    return comb

if __name__=='__main__':
    str = input()
    comb = all_comb(len(str)-1)
    tail = 0
    sum = 0
    for plus_positions in comb:
        head = 0
        for plus_position in plus_positions:
            num = int(str[head:plus_position+1])
            sum += num
            head = plus_position + 1
        num = int(str[head:])
        sum += num
    print(sum)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e7 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}


vector<LL> prime;
bool comp[MAXN];
LL f[MAXN], cnt[MAXN];

/*
	mu(p) = -1; 
	mu(p*p*..) = 0,
*/

void sieve(){
	fill(comp, comp + MAXN, 0);
	f[1] = 1;
	for(LL i = 2; i < MAXN; i++){
		if(!comp[i]){
			prime.pb(i);
			f[i] = 2;
			cnt[i] = 2;
		}
		for(auto p:prime){
			if(p*i>MAXN) break;
			comp[p*i] = 1;
			if(i%p == 0){
				f[i*p] = f[i] / cnt[i] * (cnt[i] + 1);
				cnt[i * p] = cnt[i] + 1;
				break;
			}
			f[i*p] = f[i]*f[p];
			cnt[i * p] = 2;
		}
	}
}



int main(){
  fio();
  sieve();
  LL n; cin>>n;
  LL an = 0;
  for1(i,n){
  	an+=i*f[i];
  }
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 177604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    int a;
    cin >> a;
    cout << a * a << endl;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int m;
    cin >> m;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    vector<int> c;
    set_union(all(a), all(b), back_inserter(c));
    for (int x : c) cout << x << endl;
}



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

using namespace std;

typedef long long LL;
#define N 120000

LL n,m,sum,ans,f[N];
struct node{
	LL b,l,r,d;
	bool operator < (const node &p) const{
		return d>p.d;
	}
}a[N];

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=n;++i){
		scanf("%lld%lld%lld",&a[i].b,&a[i].l,&a[i].r);
		a[i].d=a[i].b*a[i].l+(m-a[i].b)*a[i].r;
		sum+=a[i].b*a[i].l;
	}
	sort(a+1,a+n+1);
	for (LL i=1;i<=n;++i) f[i]=f[i-1]+a[i].d;
	ans=n*m;
	for (LL i=1;i<=n;++i){
		if (f[i]>=sum){
			LL l=1,r=i-1,tmp=0;
			while (l<=r){
				LL mid=(l+r)>>1;
				if (a[i].d+f[mid]>=sum){tmp=mid; r=mid-1;}
				else l=mid+1;
			}
			LL s=sum;
			s-=f[tmp];
			if (s<0) continue;
			ans=min(ans,tmp*m+(s+a[i].l-1)/a[i].l);
			ans=min(ans,tmp*m+(s+a[i].b*(a[i].r-a[i].l)+a[i].r-1)/a[i].r);
		}
		else{
			LL l=i+1,r=n,tmp=0;
			while (l<=r){
				LL mid=(l+r)>>1;
				if (f[mid]>=sum){tmp=mid; r=mid-1;}
				else l=mid+1;
			}
			LL s=sum;
			s-=f[tmp]-a[i].d;
			if (s<0) continue;
			ans=min(ans,(tmp-1)*m+(s+a[i].l-1)/a[i].l);
			ans=min(ans,(tmp-1)*m+(s+a[i].b*(a[i].r-a[i].l)+a[i].r-1)/a[i].r);
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 4736
#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 {
#ifdef LOCAL
~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;



int main() {
    int n;
    scanf("%d", &n);
    // dp[heads]
    // if we had i tosses, then tails=i-heads
    vector<double> dp(n + 1);
    // dp[i] - p-bility that there are i heads so far
    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin) {
        double p_heads;
        scanf("%lf", &p_heads);
        for(int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
    double answer = 0;
    for(int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if(heads > tails) {
            answer += dp[heads];
        }
    }
    printf("%.10lf\n", answer);
}

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

#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
using mint = modint998244353;
int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> A(N), B(M);
  REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];
  auto c = convolution(A, B);
  REP(i, N + M - 1) { cout << c[i] << " "; }
  cout << endl;
}

Measured memory_bytes: 27292
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    
    int ans = 1;
    for(int i = 0; i < N; ++i){
        ans *= 3;
    }
    
    vector<int> odd(N);
    for(int i = 0; i < N; ++i){
        if(A[i] % 2 == 0)       odd[i] = 2;
        else                    odd[i] = 1;
    }
    
    int subtraction = 1;
    for(int i = 0; i < N; ++i){
        subtraction *= odd[i];
    }
    
    ans -= subtraction;
    
    cout << ans << endl;
}

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

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

    int flag = 0;
    for(int i = 1; i < 4; i ++)
    {
    	if(s[i] == s[i - 1])
    		flag = 1;
    }
    if(flag == 1)
    	cout << "Bad" << endl;
    else
    	cout << "Good" << endl;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

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

    int n;
    cin >> n;

    vector<int> v(n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];

        while (v[i] % 2 == 0) {
            ans++;
            v[i] /= 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a[1<<19];
ll sum[1<<19][65];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ll tmp = a[i];
        for (int j = 0; j < 60; j++) {
            sum[i][j] = tmp & 1;
            tmp >>= 1;
        }
    }
    for (int i = n; i >= 0; i--) {
        for (int j = 0; j < 60; j++) {
            sum[i][j] += sum[i + 1][j];
        }
    }
    ll ans = 0;
    ll mod = 1e9 + 7;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 60; j++) {
            ans += (1LL << j) % mod * ((a[i] >> j) & 1 ? n - i - 1 - sum[i + 1][j] : sum[i+1][j]) % mod;
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}


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


int main (void)
{
    int a1, a2, a3;
    scanf("%d%d%d", &a1, &a2, &a3);
    if ((a1+a2+a3) >= 22) {
        printf("bust\n");
        return EXIT_SUCCESS;
    }
    printf("win\n");
    return EXIT_SUCCESS;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		while (true) {
			if (A + 1 < B) {
				A++;
			} else {
				A--;
				if (A < 0) {
					System.out.println("Borys");
					break;
				}
			}
			if (B - 1 > A) {
				B--;
			} else {
				B++;
				if (B > N) {
					System.out.println("Alice");
					break;
				}
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 23764
n = int(input())
r = 10**7+1
l = 1

def f(n):
  return (n**2+n)//2

while r-l> 1:
  if f((l+r)//2)>n:
    r = (l+r)//2
  else:
    l = (l+r)//2

l = l+1
rm = (l+1)*l//2-n
ans = list(range(1, l+1))
ans.remove(rm)
for a in ans:
  print(a)



Measured memory_bytes: 3572