akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7; 
const int N = 2e5+1; 
int n;

vector<int> height(N),beauty(N);

vector<long long int> tree(4*N,0); 


void update(int node , int start, int end, int idx, long long int val)
{
    if(start == end)
    {
       
        tree[node] = val;
        
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child.
            update(2*node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child.
            update(2*node+1, mid+1, end, idx, val);
        }
        
        // Internal node will have the sum of both of its children.
        tree[node] = max(tree[2*node],tree[2*node+1]);
        
    }
}


long long int query(int node, int start, int end, int l, int r)
{
    
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range.
        return 0;
        
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range.
        return tree[node];
        
    }
    
    // range represented by a node is partially inside and partially outside the given range.
    int mid = (start + end) / 2;
    long long int p1 = query(2*node, start, mid, l, r);
    long long int p2 = query(2*node+1, mid+1, end, l, r);
    return max(p1,p2);
    
}

void solve()
{
       
       cin >> n;
       
       for(int i = 0; i < n ; i ++ ) cin >> height[i];
       for(int i = 0; i < n ; i ++ ) cin >> beauty[i];
        

       
       vector< long long > dp(n);
       long long max_res = 0; 

       for(int i = n-1 ; i >= 0 ; i -- ){

        long long  next_index = query(1,1,n,height[i]+1,n);
        //cout << " range " << height[i]+1 << " " << n << endl; 
        
        //cout << " i " << height[i] << " " << next_index << endl; 
        dp[i] = beauty[i] + next_index;
        
        //cout << " updated " << dp[i] << endl ; 
        
        max_res = max(max_res,dp[i]); 
        update(1,1,n,height[i],dp[i]); 
        

       }


       cout << max_res; 


}

int main()
{

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   solve();
   return 0;
}

/**


*/




Measured memory_bytes: 12668
import java.util.*;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n =  Integer.parseInt(sc.next());
        BigDecimal bd = null;
        while(true) {
            bd = new BigDecimal(n);
            Double res = Math.sqrt(bd.doubleValue()); 
            if (new BigDecimal(res).multiply(new BigDecimal(res)).compareTo(bd) == 0) {
                System.out.println(n);
                return;
            }
            n--;
            continue;
        }
    }
}


Measured memory_bytes: 63568
# https://atcoder.jp/contests/abc006/tasks/abc006_4
 
class Array
  def lis
    b_ary = [self[0]]
    self[1..-1].each do |v|
      # 広義単調増加 { |x| x > v }
      # index = b_ary.bsearch_index { |x| x > v }
      # 狭義単調増加 { |x| x >= v }
      # index = b_ary.bsearch_index { |x| x >= v }
      # 広義単調減少 { |x| x < v }
      index = b_ary.bsearch_index  { |x| x < v }
      # 狭義単調減少 { |x| x <= v }
      # index = b_ary.bsearch_index { |x| x <= v }
      if index
        b_ary[index] = v
      else
        b_ary << v
      end
    end
    return b_ary.size
  end
end
 
n = gets.to_i
puts n.times.with_object([]) { |_i,obj| obj << gets.to_i }.lis


Measured memory_bytes: 4020
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    REP(i, N) cin >> p[i];
    sort(p.begin(), p.end());
    int s = 0;
    REP(i, K) s += p[i];
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3136
def solve(tokens):
    stack = []

    for token in tokens:
        if token == "+":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 + t2)
        elif token == "-":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t2 - t1)
        elif token == "*":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 * t2)
        else:
            stack.append(int(token))

    return stack.pop()


def main():
    print solve(raw_input().split())


if __name__ == "__main__":
    main()

Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    
    vector <int> a(n),b(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    
    for(int i=1;i<4;i++){
        
        double sum=0;
        for(int j=0;j<n;j++) sum+=abs(pow(a[j]-b[j],i));
        
        cout<<fixed<<pow(sum,1./i)<<endl;
        
    }
    
    for(int i=0;i<n;i++) a[i]-=b[i],a[i]=abs(a[i]);
    
    cout<<*max_element(a.begin(),a.end())<<endl;
    
    return 0;
    
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  if (n % 2 != 0) {
    cout << 0 << endl;
    return 0;
  }

  vector<ll> cnt;
  ll div = 2;
  FOR(i, 1, 37) {
    div *= 5;
    ll num = n / div;
    if (num == 0) break;

    cnt.push_back(num);
  }

  ll ans = 0;
  ll prev = 0;
  FORR(i, cnt.size() - 1, 0) {
    ans += (cnt[i] - prev) * (i + 1);
    prev = cnt[i];
  }

  cout << min(ans, n / 2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ng_d;
  int dd;
  vector<int> d;
  for (int i = 0; i < k; ++i) {
    cin >> dd;
    ng_d.push_back(dd);
  }
  for (int i = 0; i < 10; ++i) {
    bool ng = false;
    for (int j = 0; j < ng_d.size(); ++j) {
      if (ng_d[j] == i) {
        ng = true;
        break;
      }
    }
    if (!ng) {
      d.push_back(i);
    }
  }
  sort(d.begin(), d.end());

  int ans = d[0];
  bool ok = false;

  for (int i1 = 0; i1 < d.size(); ++i1) {
    int tmp1 = d[i1];
    if (tmp1 >= n) {
      ans = tmp1;
      goto end;
    }
  }

  for (int i1 = 0; i1 < d.size(); ++i1) {
    int tmp1 = d[i1];

    for (int i2 = 0; i2 < d.size(); ++i2) {
      int tmp2 = tmp1 * 10 + d[i2];
      if (tmp2 >= n) {
        ans = tmp2;
        goto end;
      }
    }
  }
  for (int i1 = 0; i1 < d.size(); ++i1) {
    int tmp1 = d[i1];

    for (int i2 = 0; i2 < d.size(); ++i2) {
      int tmp2 = tmp1 * 10 + d[i2];

      for (int i3 = 0; i3 < d.size(); ++i3) {
        int tmp3 = tmp2 * 10 + d[i3];
        if (tmp3 >= n) {
          ans = tmp3;
          goto end;
        }
      }
    }
  }
  for (int i1 = 0; i1 < d.size(); ++i1) {
    int tmp1 = d[i1];

    for (int i2 = 0; i2 < d.size(); ++i2) {
      int tmp2 = tmp1 * 10 + d[i2];

      for (int i3 = 0; i3 < d.size(); ++i3) {
        int tmp3 = tmp2 * 10 + d[i3];

        for (int i4 = 0; i4 < d.size(); ++i4) {
          int tmp4 = tmp3 * 10 + d[i4];

          if (tmp4 >= n) {
            ans = tmp4;
            goto end;
          }
        }
      }
    }
  }
  for (int i1 = 0; i1 < d.size(); ++i1) {
    int tmp1 = d[i1];

    for (int i2 = 0; i2 < d.size(); ++i2) {
      int tmp2 = tmp1 * 10 + d[i2];

      for (int i3 = 0; i3 < d.size(); ++i3) {
        int tmp3 = tmp2 * 10 + d[i3];

        for (int i4 = 0; i4 < d.size(); ++i4) {
          int tmp4 = tmp3 * 10 + d[i4];

          for (int i5 = 0; i5 < d.size(); ++i5) {
            int tmp5 = tmp4 * 10 + d[i5];
            if (tmp5 >= n) {
              ans = tmp5;
              goto end;
            }
          }
        }
      }
    }
  }

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


Measured memory_bytes: 3144
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let mut a: Vec<i32> = readnc();
    a.sort();

    println!("{}", a[n-1]-a[0]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


int main()
{
    string op;
    int A, B;
    cin >> A >> op >> B;

    int ans = (op == "+") ? (A+B) : (A-B);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
//ll visit[100001]={0};
//vector<ll> adj[1000001];

    
int main(){
   IOS;
int t;t=1;//cin>>t;
while(t--){
string a,b;
cin>>a>>b;ll ans=LONG_MAX;
for(ll i=0;i+b.size()<=a.size();i++){ll x=0;
    for(ll j=0;j<b.size();j++){
        if(a[i+j]!=b[j]) x++;
    }
    ans=min(ans,x);
}
cout<<ans<<"\n";
}
    
    

    
    





return 0;}


Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    cout << n - i + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define si set<int>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define sq(x) ((x) * (x))
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    int res = 0, mx = 0;
    for (int i = 0; i < n; i++)
    {
        mx = max(mx, a[i]);
        res += mx - a[i];
    }
    cout << res << endl;
    GAME_OVER;
}

Measured memory_bytes: 4776
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    string s; cin >> s;
    string t; cin >> t;
    bool flag = true;
    for(int i=0; i<s.length(); i++) {
        if(s[i]!=t[i]) flag = false;
    }
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#include<iostream>

using namespace std;

// スペルミス防止用
#define Al "Alice"
#define Bo "Borys"
#define Dr "Draw"
// Problem https://atcoder.jp/contests/agc020/tasks/agc020_a
// Ref1 https://img.atcoder.jp/agc020/editorial.pdf
// Ref2 https://atcoder.jp/contests/agc020/submissions/2171282


/** 戦略:各自最善を尽くしても負けるケース
 *  ☆相手が自分の所に詰め寄られてスペースが無くなる(二人の値の差が1になる)
 *  →逃げるしか無くなる(差が2)→さらに詰め寄られる(差が1)
 *  →紙の端と相手のコマに挟まれる→自分の負け
 *  ☆このゲームはどう動いても二人の値の差が+1か-1になる→奇数と偶数の順番になる
 *  ☆最終的には A_B (差が2)となるがこの時Aが動ければアリスの勝ち
 *  Bが動ければボリスの勝ち 
 *  ☆偶数の時にA_B状態が自分の番になるには距離の初期値が偶数の時にアリス/奇数の時に
 *   ボリスになっていればよい
 * */ 
int solver(int dice,int albegin,int bobegin){
    int result;
    result = 0; // 0 Draw 1 Alice 2 Borys
    int dist;
    dist=0;
    dist = bobegin-albegin;
    if((dist%2)==0){// 距離の初期値が偶数→Alice
        result=1;
    }
    else{
        if((dist%2)==1){// 距離の初期値が奇数→Borys
            result=2;
        }
        else{// それ以外の時→Draw(整数には偶数か奇数しかないのでナンセンスな仮定)
            result=0;
        }
    }
    return result;
}

int main(void){
    int answer;
    answer = 0;
    int N,A,B;
    cin >> N >> A >> B;
    answer=solver(N,A,B);
    if(answer == 1){
        cout << Al << endl;
        }
    else{
        if(answer == 2){
            cout << Bo << endl;
            }
            else{
                cout << Dr << endl;
            }
        }

    return 0;
}


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

#define fastio 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p;
  for(int i = 0; i < m; i++){
    int idx, val; cin >> idx >> val; idx--;
    p.push_back({idx, val});
  }
  for(int i = 0; i <= 999; i++){
    string s = to_string(i);
    if(s.size() == n){
      bool ok = true;
      for(auto c : p){
        if(s[c.first] - '0' != c.second){
          ok = false; break;
        }
      }
      if(ok){
        cout << s << '\n'; return;
      }
    }
  }
  cout << -1 << '\n';
}

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

  pre();

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

  ktj();
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,T,S,A[3010],B[3010];
int dp[3010][3010];

int f(int cur,int time){
	int& res=dp[cur][time];
	if(res!=-1)return res;
	if(cur==N)return res=0;
	res=f(cur+1,time);
	if(time+1<=T){
		res=max(res,f(cur,time+1));
	}
	if(time+B[cur] <= T && (time+B[cur]<=S || time>=S)){
		res=max(res,A[cur]+f(cur+1,time+B[cur]));
	}
	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>N>>T>>S;
	rep(i,N)cin>>A[i]>>B[i];
	memset(dp,-1,sizeof(dp));
	cout<<f(0,0)<<endl;
}

Measured memory_bytes: 36988
#include <stdio.h>

int main(void){
  int n, h, w;
  int list[1000][2];
  int i, c;

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

  for (i = 0; i < n; i++) {
    scanf("%d %d", &list[i][0], &list[i][1]);
  }

  c = 0;
  for (i = 0; i < n; i++) {
    if (list[i][0] >= h && list[i][1] >= w) {
      c++;
    }
  }

  printf("%d\n", c);

  return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    dp = [0] * 47
    dp[0] = 1
    dp[1] = 1
    for i in range(2,N+1):
        dp[i] = dp[i-1] + dp[i-2]
    print(dp[N])



if __name__ == '__main__':
    main()




Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const ll MAX_N = 100000;

//既存のsort関数で数字のときと同様にsortすればOK！

//使い方　昇順にソートしたいときは、23行目、
//   　　　降順にソートしたいときは、24行目をコメントアウトする

int main()
{
    float L;
    double tL;
    double ans=0;
    cin >> L;
    tL = L/3;
    ans = tL * tL*tL;
    printf("%lf", ans);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections
sys.setrecursionlimit(1000000)
INF = float("inf")

N = int(sys.stdin.readline())
A = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param

left=[-INF]*(N+1)
right=[-INF]*(N+1)

for i in range(N):
    left[i+1] = max(left[i],A[i])

for i in range(N)[::-1]:
    right[i] = max(right[i+1],A[i])

#print(left,right)
for i in range(N):
    #print(i,i+2)
    print(max(left[max(0,i)],right[min(N,i+1)]))

Measured memory_bytes: 16016
N,M = map(int, input().split())

def f(x):
    if M >= 2*x and N+(M-2*x)//2 >= x:
        return True
    return False

l = 0
r = 10**12
while r-l > 1:
    m = (l+r)//2
    if f(m):
        l = m
    else:
        r = m

if f(r):
    print(r)
else:
    print(l)

Measured memory_bytes: 3060
n = int(input())
answer = [0 for i in range(4)]
for i in range(n):
    s = input()
    if s == "AC":
        answer[0] += 1
    elif s == "WA":
        answer[1] += 1
    elif s == "TLE":
        answer[2] += 1
    else:
        answer[3] += 1

print("AC x", answer[0])
print("WA x", answer[1])
print("TLE x", answer[2])
print("RE x", answer[3])


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  cin >> s;
  rep(i,3){
    if(s.at(i) == '9'){
      s.at(i) = '1';
    }else if(s.at(i) == '1'){
      s.at(i) = '9';
    }
  }
  cout << s << endl;
  
}

Measured memory_bytes: 256
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int n,t,a[1010],b[1010],dp[10101010],ans=1e9;
int main()
{
	cin>>t>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<1010101;i++)
	{
		dp[i]=1e9+100;
	}
	dp[0]=0;
	for(int i=1;i<=202020;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i>=a[j])
			{
				dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
			}
		}
	}
	for(int i=t;i<=202020;i++)
	{
		ans=min(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool bubble_sort (vector<string> & a )
{
	vector<string> pre = a;
	int n = a.size();
	rep (i, n ){
		for (int j = n-1; j >= i + 1; j-- ){
			if ((int)(a[j][1] - '0' ) < (int)(a[j-1][1] - '0' ) ){
				swap (a[j], a[j-1] );
			} // end if
		} // end for
	} // end rep


	vector<string> p(10, "" ), q(10, "" );
	rep (i, n ){
		int num1 = (int)(pre[i][1] - '0' );
		p[num1] += pre[i][0];
		int num2 = (int)(a[i][1] - '0' );
		q[num2] += a[i][0];
	} // end rep

	rep (i, 10 )
		if (p[i] != q[i] ) return false;

	return true;
}

bool selection_sort (vector<string> & a )
{
	vector<string> pre = a;
	int n = a.size();

	rep (i, n ){
		int mini = i;
		for (int j = i; j < n; j++ ){
			if ((int)(a[j][1] - '0' ) < (int)(a[mini][1] - '0' ) ){
				mini = j;
			} // end if
		} // end for
		if (i != mini ){
			swap (a[i], a[mini] );
		} // end if
	} // end rep

	vector<string> p(10, "" ), q(10, "" );
	rep (i, n ){
		int num1 = (int)(pre[i][1] - '0' );
		p[num1] += pre[i][0];
		int num2 = (int)(a[i][1] - '0' );
		q[num2] += a[i][0];
	} // end rep

	rep (i, 10 )
		if (p[i] != q[i] ) return false;

	return true;
}
int main()
{
	int n; cin >> n;
	vector<string> a (n, "" );
	rep (i, n ) cin >> a[i];

	vector<string> ans1 = a, ans2 = a;
	bool res1 = bubble_sort (ans1 );
	bool res2 = selection_sort (ans2 );

	rep (i, n ) cout << ans1[i] << (i != n - 1 ? ' ' : '\n' );
	cout << (res1 ? "Stable" : "Not stable" ) << endl;
	rep (i, n ) cout << ans2[i] << (i != n - 1 ? ' ' : '\n' );
	cout << (res2 ? "Stable" : "Not stable" ) << endl;

	return 0;
}

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

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

    string s;
    cin >> s;

    int ans = 1;;
    char bef = s[0];
    for(int i = 1; i < s.size(); i++){
        if(i == s.size() - 1 && s[i] == bef){
            break;
        }
        if(bef == s[i]){
            i++;
            bef = '1';
        }else{
            bef = s[i];
        }
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 720
import java.io.*;
import java.util.Scanner;


public class Main{
    public static void main(String[] args) throws IOException
    {
        Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
 
        do{
            String line1 = scanner.next();
            String line2 = scanner.next();

            int n = Integer.parseInt(line1);
            int x = Integer.parseInt(line2);
            if(n == 0 && x == 0){
                break;
            }
            int count = 0;

            for(int i = 1;i < n-1;i++){
                for(int j = i+1;j < n; j++){
                    for(int k = j + 1;k <= n;k++){
                        if(i + j + k == x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }while(true);
       
    }
}




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

int main()
{
	double ans=0.0;
	double now = 0.0;
	int n, k;
	cin >>n>>k;
	vector<int>p(n,0.0);
	vector<double> E(n, 0.0);
	for(int i=0;i<n;i++){
		cin >>p[i];
		E[i]=(1+p[i])*(p[i]/2.0)/p[i];
	//	printf("%.9lf\n", E[i]);
	}
	for(int i=0;i<n;i++){
		
		if(i <k){
			now+=E[i];
		}else{
			now=now-E[i-k]+E[i];
		}
		chmax(ans, now);
	//	printf("%.9lf\n", ans);
	}

	printf("%.9lf\n",ans);
}

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

#define f first
#define s second
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

#define x1 aseasfd                         	
#define y1 sadasd
#define left come
#define right sdsfd

using namespace std;

const int maxn = 1e6 + 7;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
const ld eps = (ld)1e-12;
const double pi = 3.141592653;
const ll linf = 1e18 + 7;
const int logn = 20;                                                             

int n,a[205];
         
int main () {

cin >> n;

n *= 2;
for (int i = 1; i <= n; i ++) {
	cin >> a[i];
}


sort (a + 1, a + n + 1);

if (n & 1) {
	int ans = 0;
	for (int i = n; i >= 2; i -= 2) {
		ans += min(a[i], a[i - 1]);
	}cout << ans;              
}

else {
	int ans = 0;
	for (int i = n; i >= 1; i -= 2) {
		ans += min(a[i], a[i - 1]);
	}
	cout << ans;
}

return 0;
}

Measured memory_bytes: 256
H, N = map(int, input().split())
ms = []
for _ in range(N):
    h, c = map(int, input().split())
    ms.append((h, c))
inf = 10**18
dp = [inf] * (H+1)
dp[0] = 0
for i in range(1, H+1):
    for h, c in ms:
        dp[i] = min(dp[i], dp[max(i-h, 0)] + c)
print(dp[-1])


Measured memory_bytes: 41964
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	float s = 0;
	vector<float>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	s = (a[0] + a[1]) / 2;
	for (int i = 2; i < n; i++) {
		s = (s + a[i]) / 2;
	}
	cout << s << endl;
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  ll a[200005];
  ll s[200005];
  ll sum=0;
  for (int i=0; i<n; i++) {
    cin>>a[i];
    sum+=a[i];
    s[i]=sum;
  }
  ll ans=1e18;
  for (int i=0; i<n-1; i++) {
    ans=min(ans,abs(sum-s[i]*2));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3328
def myAnswer(H:int,W:int,A:list) -> None:
   ans = []
   for a in A:
      for i in a:
         if(i == "#"):
            ans.append(a)
            break
         
   ansT = list(zip(*ans))
   ans = []
   for t in ansT:
      for i in t:
         if(i == "#"):
            ans.append(t)
            break
   ans = list(zip(*ans))
   for a in ans:
      string = ""
      for i in a:
         string +=i
      print(string)


def modelAnswer():
   return
def main():
   H,W = map(int,input().split())
   A = []
   for _ in range(H):
      A.append(list(input()))
   myAnswer(H,W,A[:])
if __name__ == '__main__':
   main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string s;
  cin >> s;
  ll k=s.size();
  ll a=0,b=0,c=0;
  rep(i,k){
    if(s[i]=='a'){
      a++;
    }
    else if(s[i]=='b'){
      b++;
    }
    else
      c++;
  }
  if(max(max(a,b),c)-min(min(a,b),c)<=1){
    cout << "YES" << endl;
  }
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc;
    //string s="";
    LL limit = 13;
    vector<LL> powers(14);
    vector<LL> sum(14);
    for (i = 0; i <= limit; i++)
    {
        powers[i] = POW(26, i);
        //debug(powers[i]);
    }

    sum[0] = 0;
    for (i = 1; i <= limit; i++)
    {
        sum[i] = powers[i] + sum[i - 1];
//debug(sum[i]);
    }
    string s = "";

    cin >> n;
    LL pos;
    for (i = 1; i <= limit; i++)
    {
        if (n <= sum[i] && n > sum[i - 1])
        {
            pos = i;
        }
    }

   // debug(pos);
    LL curr = n;

    for (i = pos; i >= 1; i--)
    {
       // part;
        LL base = sum[i - 1];
        LL dis = curr - base;
        //debug(base);
        //debug(curr);
        int now = dis%26;
        if(now==0)
        {
            now=26;
        }
        char now_a = (char)(now-1 + 'a');
        s = now_a + s;
        LL add=0;
        if(i>=2)
        {
            add=sum[i-2];
        }
        curr = (curr - base - now) / 26 + 1+add;

       // debug(dis);
       // debug(now);
       // debug(now_a);
       // part;
    }
cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N, X, M;
ll A[300000];

ll Last;
ll Start;
map<ll, ll> mp;
int main() {
    cin >> N >> X >> M;
    A[0] = X;
    mp[X] = 0;
    for(int i = 1; ; i++) {
        A[i] = (A[i-1] * A[i-1]) % M;
        if(mp.count(A[i])) {
            Last = i;
            Start = mp[A[i]];
            break;
        }
        mp[A[i]] = i;
    }
    /*
    for(int i = 0; i <= Last; i++) {
        cerr << i << " " << A[i] << endl;
    }
    */
    ll ans = 0;
    if(N <= Last) {
        for(int i = 0; i < N; i++) ans += A[i];
    } else {
        for(int i = 0; i < Start; i++) ans += A[i];
        ll sum = 0;
        for(int i = Start; i < Last; i++) sum += A[i];
        ans += sum * ((N - Start) / (Last - Start));
        ll rest = N - Start - (Last - Start) * ((N - (Start)) / (Last - Start));
        //cerr << Start << " "<< Last << " " << sum << " " << rest << endl;
        for(int i = 0; i < rest; i++) ans += A[Start+i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7104
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
int N, C;

int s[MAXN], t[MAXN], c[MAXN];
int needed[MAXN * 2], prefix[MAXN * 2];
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> C;
    for (int i = 0; i < N; ++i){
        cin >> s[i] >> t[i] >> c[i];
    }
    memset(needed, 0, sizeof needed);
    for (int i = 1; i <= C; ++i){
        memset(prefix, 0, sizeof prefix);
        for (int j = 0; j < N; ++j){
            if (c[j] == i){
                prefix[s[j] * 2 - 1]++;
                prefix[t[j] * 2]--;
            }
        }
        for (int j = 1; j < MAXN * 2; ++j){
            prefix[j] += prefix[j-1];
        }
        for (int j = 0; j < MAXN * 2; ++j){
            if (prefix[j]) needed[j]++;
        }
    }
    int answer = 0;
    for (int i = 0; i < MAXN * 2; ++i){
        answer = max(answer, needed[i]);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
int main(){
  int n,a;

  while(scanf("%d",&a)!=EOF){
    int min,max;
    int i,k=1;
    n=a;
    if(n%2==0)n++;
    for(min=n-2;min>0;min-=2){
      k=1;
      for(i=3;i*i<min;i+=2){
	if(min%i==0){
	  k=0;
	  break;
	}
      }
      if(k){
	if(min==1)min++;
	printf("%d ",min);
	break;
      }
    }
    if(a%2==0)n-=2;
    for(max=n;max>0;max+=2){
      k=1;
      for(i=3;i*i<max;i+=2){
	if(max%i==0){
	  k=0;
	  break;
	}
      }
      if(k&&(n!=max)){
	printf("%d\n",max);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define vpii vector<pair<int,int> >
#define X first
#define Y second
#define fr(i,a,n) for(int i=a;i<n;i++)
#define frr(i,n,a) for(int i=n;i>=a;i--)
#define mod 1000000007
#define fi ios_base::sync_with_stdio(false);cin.tie(NULL);


int main()
{
   int n,k;
   cin>>n>>k;
   int a[n+1],b[n+1];
   fr(i,0,n)
   {
      cin>>a[i];
   }
int j=0;
k--;
int ans=INT_MAX;
   while(k<n)
   {
      if(a[j]<0 && a[k]>0)
      {
         if(abs(a[j])<=a[k])
      ans=min(ans,2*abs(a[j])+a[k]);
      else
      ans=min(ans,2*a[k]+abs(a[j]));
      }
      else
      {
         ans=min(ans,max(abs(a[j]),abs(a[k])));
      }
      k++;
      j++;
   }
   cout<<ans;
   
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N;
    while (cin >> N, N) {
        vector<int> A(N);
        rep(i, N) cin >> A[i];
        ll ans = INFLL;

        for (int g=0; g<(1<<N); g++) {
            ll sum1 = 0, sum2 = 0;
            for (int i=0; i<N; i++) {
                (g>>i & 1 ? sum1 : sum2) += A[i];
            }
            ans = min(ans, abs(sum1 - sum2));
        }

        cout << ans << endl;
    }
}

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

int main() {
      int N,X;
      cin>>N>>X;
      int L[N+10];
      int D=0;
      for(int i=0;i<N;i++){
            cin>>L[i];
      }
      for(int j=1;j<=N+1;j++){
            D+=L[j-1];
            if(D>X){
                  cout<<j<<endl;
                  break;
            }
            if(D==X){
                  cout<<j+1<<endl;
                  break;
            }
      }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, M;
    cin >> N >> M;
    vi A(M), B(M);
    vector<int> C(M);
    rep(i, 0, M) {
        cin >> A[i];
        cin >> B[i];
        C[i] = 0;
        rep(j, 0, B[i]) {
            int x;
            cin >> x;
            x--;
            C[i] |= 1 << x;
        }
    }

    vvi dp(M + 1, vi(1 << N, INF));
    dp[0][0] = 0;
    rep(i, 0, M) {
        rep(j, 0, 1 << N) {
            chmin(dp[i + 1][j | C[i]], dp[i][j] + A[i]);
            chmin(dp[i + 1][j], dp[i][j]);
        }
    }
    int ans = dp[M][(1 << N) - 1];
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 32384
#include <vector>
#include <type_traits>
#include <iterator>
#include <cassert>

namespace tools {
  template <typename T> class fenwick {
  private:
    std::vector<T> values;

  public:
    template <
      typename InputIter,
      typename std::enable_if<
        std::is_same<T, typename std::iterator_traits<InputIter>::value_type>::value &&
        std::is_base_of<std::input_iterator_tag, typename std::iterator_traits<InputIter>::iterator_category>::value,
        std::nullptr_t
      >::type = nullptr
    > fenwick(const InputIter begin, const InputIter end) :
      values(begin, end) {
      for (std::size_t i = 1; i < this->values.size(); ++i) {
        if (i + (i & -i) - 1 < this->values.size()) {
          this->values[i + (i & -i) - 1] += this->values[i - 1];
        }
      }
    }

    std::size_t size() const {
      return this->values.size();
    }

    void add(std::size_t i, const T value) {
      assert(i < this->values.size());
      for (i += 1; i <= this->values.size(); i += i & -i) {
        this->values[i - 1] += value;
      }
    }

    T sum(const std::size_t begin, const std::size_t end) const {
      if (begin == 0) {
        assert(end <= this->values.size());
        T result = 0;
        for (std::size_t i = end; i > 0; i -= i & -i) {
          result += this->values[i - 1];
        }
        return result;
      } else {
        return begin < end ? this->sum(0, end) - this->sum(0, begin) : 0;
      }
    }

    T operator[](const std::size_t i) const {
      return this->sum(i, i + 1);
    }
  };
}

#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cassert>
#include <cstdlib>

std::int_fast64_t solve(const tools::fenwick<std::int_fast64_t>& a_fenwick, const std::int_fast64_t first_target) {
  assert(first_target == 1 || first_target == -1);
  tools::fenwick<std::int_fast64_t> work = a_fenwick;
  std::int_fast64_t target = first_target;
  std::int_fast64_t result = 0;
  for (std::size_t i = 0; i < work.size(); ++i, target *= -1) {
    const std::int_fast64_t current_sum = work.sum(0, i + 1);
    const std::int_fast64_t diff = (target > 0 ? current_sum < target : target < current_sum) ? target - current_sum : 0;
    result += std::abs(diff);
    work.add(i, diff);
  }
  return result;
}

int main() {
  std::int_fast64_t n;
  std::cin >> n;
  std::vector<std::int_fast64_t> a(n);
  std::copy_n(std::istream_iterator<std::int_fast64_t>(std::cin), n, a.begin());
  tools::fenwick<std::int_fast64_t> a_fenwick(a.begin(), a.end());

  std::cout << std::min(solve(a_fenwick, 1), solve(a_fenwick, -1)) << std::endl;
  return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

int result[20001][256];

int main()
{
    int n, m;
    while(1){
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        int c[17];
        int x[20001];
        for(int i = 0; i < m; i++){
            cin >> c[i];
        }
        for(int j = 0; j < n; j++){
            cin >> x[j];
        }
        
        // result[i][j] : i???????????????j?????£?????¨?????????????????§???????????±?????????????°????
        for(int i = 0; i < n + 1; i++){
            for(int j = 0; j < 256; j++){
                result[i][j] = -1;
            }
        }
        for(int i = 0; i < m; i++){
            int tmp = 128 + c[i];
            if(tmp > 255) tmp = 255;
            if(tmp < 0) tmp = 0;
            result[0][tmp] = (tmp - x[0]) * (tmp - x[0]);
        }
        for(int i = 1; i < n; i++){
            for(int j = 0; j < 256; j++){
                if(result[i - 1][j] == -1) continue;
                for(int k = 0; k < m; k++){
                    int tmp = j + c[k];
                    if(tmp > 255) tmp = 255;
                    if(tmp < 0) tmp = 0;
                    if(result[i][tmp] == -1 || result[i][tmp] > result[i - 1][j] + (tmp - x[i]) * (tmp - x[i])){
                        result[i][tmp] = result[i - 1][j] + (tmp - x[i]) * (tmp - x[i]);
                    }
                }
            }
        }
        // for(int i = 0; i < n; i++){
        //     for(int j = 0; j < 256; j++){
        //         cout << result[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        int ans = 100000000;
        for(int i = 0; i < 256; i++){
            if(result[n - 1][i] != -1) ans = min(ans, result[n - 1][i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 21236
A, B = (int(i) for i in input().split())
result = 0
cnt = 0
while(cnt < 2):
    if A < B:
        result += B
        B = B - 1
    elif A > B:
        result += A
        A = A - 1
    else:
        result += A
    cnt += 1
    
print(result)
    

Measured memory_bytes: 2940
N,M = map(int,input().split())

if M == 0:
  print(0,0)
  exit();

x = {}  
for _ in range(M):
  a,w = map(str,input().split())
  x.setdefault(int(a),[]).append(w)
  
ac = at = wa = wt = 0  
for k,v in x.items():
  for j in v:
    if j == 'AC':
      at += 1
      break
    elif j =='WA':
      wt += 1
  if at == 0:
    wt = 0
  else:
    ac += at
    wa += wt
    at = 0
    wt = 0
      
print(ac,wa)      

Measured memory_bytes: 29384