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

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}


ll dp[18][1<<18];
ll dpsub[1<<18];

signed main(){
    int n;cin>>n;
    ll x[n],y[n],p[n];
    rep(i,n)cin>>x[i]>>y[i]>>p[i];

    rep(i,n){
        rep(j,(1<<n))dp[i+1][j]=LINF;
    }

    for(int i=0;i<(1<<n);i++){
        rep(j,n)if((i>>j)&1){
            dp[0][i]+=p[j]*min(abs(x[j]),abs(y[j]));
        }
    }

    // dpsub
    for(int bit=1;bit<(1<<n);bit++){
        ll res=LINF;
        // cout<<bitset<3>(bit)<<endl;
        // x
        {
            rep(i,n)if((bit>>i)&1){
                // iに建てる
                ll xp=x[i],cost=0;
                rep(j,n)if((bit>>j)&1){
                    cost+=p[j]*abs(xp-x[j]);
                }
                chmin(res,cost);
            }   
        }
        // y
        {
            rep(i,n)if((bit>>i)&1){
                // iに建てる
                ll yp=y[i],cost=0;
                rep(j,n)if((bit>>j)&1){
                    cost+=p[j]*abs(yp-y[j]);
                }
                chmin(res,cost);
            }   
        }
        dpsub[bit]=res;
    }


    rep(i,n){
        for(int bit=0;bit<(1<<n);bit++){
            chmin(dp[i+1][bit],dp[i][bit]);
            int rem=(1<<n)-1;
            rem^=bit;

            // 部分集合列挙
            int subset=rem;
            do{
                chmin(dp[i+1][subset|bit],dp[i][bit]+dpsub[subset]);
                subset=(subset-1)&rem;
            }while(subset!=rem);
        }
    }


    rep(i,n+1){
        cout<<dp[i][(1<<n)-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 7940
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926535898
int main(){
    int a,b,h,m;
    double num,p;
    cin>>a>>b>>h>>m;
    num=2*pi*abs(1.0*m/60-1.0*(60*h+m)/720);
    p=sqrt(a*a+b*b-cos(num)*2*a*b);
    printf("%.11lf",p);

    return 0;
}

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

typedef long long ll;
typedef int64_t in;
using namespace std;
#define INF 1000000007
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)


int main() {
    int n; cin >> n;
    int u,k,v;
    int a[n][n] = {};
    rep(i,n){
        cin >> u >> k;
        rep(j, k){
            cin >> v;
            a[i][v-1]++;
        }
    }
    rep(i,n){
        rep(j,n){
            if(j!=n-1) cout << a[i][j] << " ";
            else cout << a[i][j] << endl;
        }
    }
}


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

int main() {
  int n,m;
  cin >> n >> m;
  int a[n],b[m];
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<m; i++) cin >> b[i];
  int ans=0;
  for(int i=0; i<m; i++) {
    int k=i,cnt=0;
    for(int j=0; j<n; j++) {
      if(k<m&&a[j]==b[k]) {
        k++;
        cnt++;
      }
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}


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

function main()
	n,m,v,p = readline() |> split |> parseMap
	a = readline() |> split |> parseMap |> sort
	l = 0
	r = n+1
	while r-l>1
		md = (l+r)>>1
		s = m*(md+p-1)
		for i in md+1:n-p+1
			s += max(0,a[md]+m-a[i])
		end
		if s<v*m||a[md]+m<a[n-p+1]
			l = md
		else
			r = md
		end
	end
	println(n-l)
end

main()

Measured memory_bytes: 171372
n = int(input())

happy = 0
if n // 500 >= 1:
    ha500 = n // 500
    happy = 1000 * ha500
    nokon = n % 500
    if nokon // 5 >= 1:
        ha005 = nokon // 5
        happy = happy + 5 * ha005
else:
    if n // 5 >= 1:
        ha005 = n // 5
        happy = 5 * ha005
print(happy)

Measured memory_bytes: 3060
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

#define all(x) x.begin(), x.end()
#define all_r(x) x.rbegin(), x.rend()
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, n) for(int i = n; i >= 0; --i)
#define f first
#define s second

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vi a(n), b(m);
	vector<ll> pa(n + 1), pb(m + 1);
	FOR(i, n) cin >> a[i];
	FOR(i, m) cin >> b[i];
	pa[0] = pb[0] = 0;
	FOR(i, n) pa[i + 1] = pa[i] + a[i];
	FOR(i, m) pb[i + 1] = pb[i] + b[i];
	int high = m, books = 0;
	for(int i = 0; i <= n; ++i) {
		while(high > 0 && pb[high] + pa[i] > k) --high;
		if(pa[i] + pb[high] <= k)
			books = max(books, i + high);
	}
	cout << books << '\n';
 	return 0;
}

Measured memory_bytes: 7924
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi a;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    a.resize(n);
    rep(i,n){
        cin>>a[i];
    }
    matrix dp;
    if(n%2==0){
        dp.resize(2,Vi(n+1,-INF));
    }else{
        dp.resize(3,Vi(n+1,-INF));
    }
    dp[0][0] = 0;
    rep(i,n){
        rep(j,dp.size()){
            ll now = (i-j)/2;//now個選んでる
            if(now<0)continue;
            if(dp[j][i]==-INF)continue;
            repi(k,j,dp.size()){
                if(i+k-j+1 < n)chmax(dp[k][i+k-j+2],dp[j][i]+a[i+1+k-j]);
                if(now==0)dp[k][i+k-j+1] = dp[j][i] + a[i+k-j];
            }
        }
    }
    ll ans = -INF;
    rep(i,dp.size()){
        chmax(ans,dp[i][n+i-dp.size()+1]);
    }
    print(ans);
    return 0;
}

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

using namespace std;

int main()
{
	int N, m = 0, mi;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (abs(a) >= abs(m))
			m = a, mi = i;
	}
	cout << N * 2 - 2 << '\n';
	for (int i = 0; i < N; i++)
		if (i != mi) cout << mi + 1 << ' ' << i + 1 << '\n';
	for (int i = 1; i < N; i++) {
		if (m < 0) cout << N + 1 - i << ' ' << N - i << '\n';
		else cout << i << ' ' << i + 1 << '\n';
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
import bisect
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
acc = [0]
acc0 = [0]*(n+1)
for i in range(n):
  acc.append(acc[-1]^a[i])
  if i:
    acc0[i+1] += acc0[i]
  if acc[-1] == 0:
    acc0[i+1] += 1
if acc[-1] != 0:
  s = acc[-1]
  ansls = []
  cnt0 = 0
  cnts = 0
  flg = 0
  dp = [0,0]
  for i in range(1,n+1):
    if acc[i] == s:
      dp = [dp[0]+dp[1]+1,dp[1]]
    elif acc[i] == 0:
      dp = [dp[0],dp[0]+dp[1]]
    dp[0] %= mod
    dp[1] %= mod
  print((dp[1]+1)%mod)
else:
  dcn = defaultdict(list)
  dp = defaultdict(list)
  c0 = 0
  for i in range(1,n+1):
    if acc[i]:
      dcn[acc[i]].append(i)
    else:
      c0 += 1
  ans = pow(2,c0-1,mod)
  for i in range(1,n+1):
    t = acc[i]
    if t:
      if not dp[t]:
        dp[t] = [1,0]
      else:
        idx = bisect.bisect_left(dcn[t],i)
        n0 = acc0[i]-acc0[dcn[t][idx-1]]
        dp[t][1] += n0*dp[t][0]
        dp[t][0] += dp[t][1]+1
        dp[t][0] %= mod
        dp[t][1] %= mod
  for t,ls in dp.items():
    ans += ls[0]
    ans %= mod
  print(ans)

Measured memory_bytes: 128180
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>


using namespace std;
#define MAX 100000

int main(){
    int H, W;
    vector<vector<char>> a;

    cin >> H >> W;

    for (int i = 0; i < H; i++){
        vector<char> atemp;
        a.push_back(atemp);

        for (int ii = 0; ii < W; ii++){
            char tmp;
            cin >> tmp;
            a[i].push_back(tmp);
        }
    }

    for (unsigned int i = 0; i < a.size(); i++){
        int icnt = 0;
        for (icnt = 0; icnt < W; icnt++){
            if ('#' == a[i][icnt]){
                break;
            }
        }

        if (W == icnt){
            a.erase(a.begin() + i);
            i--;
        }
    }

    for (unsigned int i = 0; i < a[0].size(); i++){
        unsigned int jcnt = 0;
        for (jcnt = 0; jcnt < a.size(); jcnt++){
            if ('#' == a[jcnt][i]){
                break;
            }
        }
        if (a.size() == jcnt){
            for (unsigned int ii = 0; ii < a.size(); ii++){
                a[ii].erase(a[ii].begin() + i);
            }
            i--;
        }
    }
    
    for (unsigned int i = 0; i < a.size(); i++){
        for (char ii : a[i]){
            cout << ii;
        }
        cout << "\n";
    }
    return 0;
}

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

int main(){
    char s[3];
    int num=0;
    for(int i=0;i<3;i++){
        cin>>s[i];
        if(s[i]=='R')
        num++;
    }
    if(num==0){
        cout<<0<<endl;
    }
    if(num==1){
        cout<<1<<endl;
    }
    if(num==2){
        if(s[1]=='R'){
            cout<<2<<endl;
        }
        else
        cout<<1<<endl;
    }
    if(num==3){
        cout<<3<<endl;
    }
    return 0;
}
    

Measured memory_bytes: 3588
#pragma GCC optimize ("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long; using uint = unsigned int; using uInt = unsigned long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rer(i,l,r) for(int i=(l); i<=(r); ++i)
#define gnr(i,l,r) for(int i=(r); i>=(l); --i)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
#define fil(a,v) memset((a),v,sizeof(a))
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;


int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  cin>>n>>m;
  int ans=0;
  ans+=(max(0,4-n))*1e5; ans+=(max(0,4-m))*1e5; if(n==1&&m==1)ans+=4e5;
  END
}

Measured memory_bytes: 256
#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>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    vector<int> copy(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        copy[i] = a[i];
    }
    sort(copy.begin(), copy.end());
    int ans = 1500000000;
    for(int i = 0; i < n; i++){
        //bool checker = false;
        vector<int> clear;
        /*for(int j = 0; j < n; j++){
            if(checker == true){
                if((j + k - 1) >= n){
                    clear.push_back(a[j]);
                    continue;
                }
                if(a[j + k - 1] < copy[i]){
                    checker = false;
                    j = j + k - 1 + k - 1;
                    continue;
                } else {
                    clear.push_back(a[j]);
                    continue;
                }
            }
            bool checker2 = true;
            for(int l = j - k + 1; l <= j + k - 1; l++){
                if(l < 0){
                    continue;
                }
                if(l >= n){
                    break;
                }
                if(a[l] < copy[i]){
                    checker2 = false;
                    j = l + k - 1;
                    break;
                }
            }
            if(checker2 == true){
                clear.push_back(a[j]);
                checker = true;
            }
        }*/
        int checker = -1;
        int j = 0;
        while(j < n){
            if(a[j] < copy[i]){
                vector<int> sub;
                for(int l = checker + 1; l < j; l++){
                    sub.push_back(a[l]);
                }
                if(sub.size() < k){
                    checker = j;
                    j++;
                    continue;
                }
                sort(sub.begin(), sub.end());
                for(int l = 0; l < sub.size() - k + 1; l++){
                    clear.push_back(sub[l]);
                }
                checker = j;
                j++;
                continue;
            }
            j++;
        }
        vector<int> sub;
        for(int l = checker + 1; l < n; l++){
            sub.push_back(a[l]);
            //cout << a[l] << endl;
        }
        if(sub.size() >= k){
            sort(sub.begin(), sub.end());
            for(int l = 0; l < (sub.size() - k + 1); l++){
                clear.push_back(sub[l]);
            }
        }
        if(clear.size() < q){
              break;
        }
        sort(clear.begin(), clear.end());
        ans = min(ans, clear[q - 1] - clear[0]);
        //for(int i = 0; i < clear.size(); i++){
        //    cout << clear[i] << endl;
        //}
        //cout << copy[i] << " cleared." << clear.size()<< endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn solve(o: Vec<char>, e: Vec<char>) -> String {
    let mut res = String::new();
    for (i, j) in o.iter().zip(&e) {
        res.push(*i);
        res.push(*j);
    }
    if o.len() > e.len() {
        res.push(o[o.len()-1])
    }
    res
}



fn main() {
    input! {
        o: chars,
        b: chars
    };
    println!("{}", solve(o, b));
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli H = 300*2+10;
lli W = 300*2+10;
lli h,w;
mat s;
lli ans = 0;

int main(){
  cin >> h >> w;
  s = mat(H, vll(W));
  for(lli i = 1;i <= h;i++){
    for(lli j = 1;j <= w;j++){
      char c;
      cin >> c;
      if(c == '#') s[i+j][i-j+300] = 1;
      else s[i+j][i-j+300] = 0;
    }
  }
  mat x = s;
  mat y = s;
  for(lli i = 0;i < H;i++) for(lli j = 1;j < W;j++) x[i][j] += x[i][j-1];
  for(lli i = 0;i < W;i++) for(lli j = 1;j < H;j++) y[j][i] += y[j-1][i];
  for(lli i = 0;i < H;i++){
    for(lli from = 0;from < W;from++){
      if(s[i][from] != 1) continue;
      for(lli to = from+1;to < W;to++){
        if(s[i][to] == 1){
          lli d = to-from;
          if(i-d >= 0){
            ans += x[i-d][to]-x[i-d][from-1];
          }
          if(i+d < H){
            ans += x[i+d][to]-x[i+d][from-1];
          }
        }
      }
    }
  }
  for(lli i = 0;i < W;i++){
    for(lli from = 0;from < H;from++){
      if(s[from][i] != 1) continue;
      for(lli to = from+1;to < H;to++){
        if(s[to][i] == 1){
          lli d = to-from;
          if(i-d >= 0){
            ans += y[to-1][i-d]-y[from][i-d];
          }
          if(i+d < W){
            ans += y[to-1][i+d]-y[from][i+d];
          }
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 9088
#include <cstdio>
#include <algorithm>
#define maxn 2005
#define LL long long
using namespace std;
LL dp[maxn][maxn];
struct node{
	int seq,val;
}a[maxn];
int cmp(node a,node b){
	return a.val<b.val;
}
int main(){//大的值最后放
	int i,j,len,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i].val),a[i].seq=i;
	sort(a+1,a+1+n,cmp);//按值自小到大排序
	for(i=1;i<=n;i++)dp[i][i]=(LL)a[1].val*abs(a[1].seq-i);//神奇的初始化
	for(len=2;len<=n;len++)//区间长度
		for(i=1;i+len-1<=n;i++){//左边界
			j=i+len-1;//右边界
			dp[i][j]=max(dp[i+1][j]+(LL)a[len].val*abs(a[len].seq-i),dp[i][j-1]+(LL)a[len].val*abs(a[len].seq-j));
		}
	printf("%lld\n",dp[1][n]);
	//printf("%lld\n",dp[1][2]);
	return 0;
}

Measured memory_bytes: 24340
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp*/

#include <list>
#include <algorithm>
#include <iostream>

using namespace std;

int main(){
    int n;
    list<int> data;
    string command;
    int value;
    list<int>::iterator it;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>command;
        if(command=="deleteFirst"){
            data.pop_front();
        }else if(command=="deleteLast"){
            data.pop_back();
        }else{
            cin>>value;
            if(command=="insert"){
                data.push_front(value);
            }else{
                it=find(data.begin(),data.end(),value);
                if(it!=data.end()){
                    data.erase(it);
                }
            }
        }
    }
    it=data.begin();
    while(it!=data.end()){
        cout<<*it++;
        if(it!=data.end()){
            cout<<" ";
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 32472
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  string s;  cin >> s;
  int n = s.size();
  int cnt = 0;
  rep0(i,s.size()/2){
    if(s[i] != s[n-i-1]){
      cnt++;
    }
  }
  cout << cnt;
}


Measured memory_bytes: 256
#include<stdio.h>
int max=0;
int n,m,q;
int s[15];
int a[60],b[60],c[60],d[60];
void roop(int k,int l){
  int i,sum=0;
  int j;
  if(k>n){
    return;
  }
  if(k==n){
    /*for(i=0;i<n;i++){
      printf("%d ",s[i]);
    }
    printf("\n");*/
    for(i=0;i<q;i++){

      if(s[b[i]-1]-s[a[i]-1]==c[i]){
        sum+=d[i];
      }

    }
    //printf("sum=%d\n",sum);
    if(max<sum){
      max=sum;
      /*for(j=0;j<q;j++){
        if(s[b[j]]-s[a[j]]==c[j]){
          printf("-%d\n",d[j]);
        }
      }*/
    }
  }
  if(l>m){
    return;
  }
  roop(k,l+1);
  s[k]=l;
  roop(k+1,l);
  //roop(k+1,l+1);
  return;
}
int main(void){
  int i;

  scanf("%d%d%d",&n,&m,&q);
  for(i=0;i<q;i++){
    scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
  }
  roop(0,1);
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 1688
n = int(input())
a = list(map(int, input().split()))

def swap(list, pos1, pos2) :
  list[pos1], list[pos2] = list[pos2], list[pos1]
  return list

ok = 0
for i in range(n):
  for j in range(i, n):
    b = a.copy()
    swap(b, i, j)
    flag = 1
    for k in range(1, n):
      if b[k - 1] > b[k]:
        flag = 0

    if flag == 1:
      ok = 1

if ok == 1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, k;
string s;
int main() {
	cin >> n >> s >> k;
	k--;
	REP(i, n) {
		if (s[i] != s[k])s[i] = '*';
	}
	cout << s << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  rep(i,h) cin >> v[i];
  rep(i,h) {
    rep(j,2) cout << v[i] << endl;
  }
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3656
s = str(input())
flag = True
n = len(s)
for i in range(n):
  if i%2 == 0:
    if s[i] == "L":
      flag = False
      break
  else:
    if s[i] == "R":
      flag = False
      break
if flag == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define inin freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
const ll N=200005;
const ll MOD=998244353;

ll fact[N];
ll invfact[N];


ll Power(ll base , ll e)
{
    if(e == 0) return 1;
    ll ans = base; e--;
    while(e)
  {
        if(e & 1) ans = (((ans%MOD) * (base%MOD)) %MOD+MOD)%MOD;
        base = (((base%MOD) * (base%MOD)) %MOD+MOD)%MOD;
        e >>= 1;
  }
  return (ans+MOD) %MOD;
}


 ll modinv(ll k)
    {
        return Power(k, MOD-2);
    }



void precompute()
    {
        fact[0]=fact[1]=1;
        for(ll i=2;i<N;i++)
        {
            fact[i]=fact[i-1]*i;
            fact[i]%=MOD;
        }
        invfact[N-1]=modinv(fact[N-1]);
        for(ll i=N-2;i>=0;i--)
        {
            invfact[i]=invfact[i+1]*(i+1);
            invfact[i]%=MOD;
        }
    }

    ll nCr(ll x, ll y)
    {
        if(y>x)
            return 0;
        ll num=fact[x];
        num*=invfact[y];
        num%=MOD;
        num*=invfact[x-y];
        num%=MOD;
        return num;
    }




int main(){
    //inin
    IOS
    ll n,m,k;
    cin>>n>>m>>k;
    precompute();
    ll ans=0;
    FOR(i,0,k){
    	ll tmp=(nCr(n-1,i)*Power(m-1,n-i-1))%MOD;
    	tmp=(tmp*m)%MOD;
    	ans=(ans+tmp)%MOD;
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
int n;
long long m,a[105],b[105],dp[105][100005],ans=0;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(j-a[i]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i]]+b[i]);
			else dp[i][j]=dp[i-1][j];
			ans=max(ans,dp[i][j]);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 81676
import sys
input = sys.stdin.readline

N = int(input())
A0 = list(map(int, input().split()))
A1 = list(map(int, input().split()))

ans = 0
for i in range(N):
    n = sum(A0[:i+1]) + sum(A1[i:N])
    ans = max(ans, n)
print(ans)


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

int main(){

    ll N;
    cin >> N;

    bool flg = false;
    vector<int> ans(N+1);

    for(int a=1; a<=sqrt(N); a++){
        for(int b=1; b<=sqrt(N); b++){
            for(int c=1; c<=sqrt(N); c++){
                int buf = a*a + b*b + c*c + a*b + b*c + c*a;
                if(a*a + b*b + c*c + a*b + b*c + c*a <= N) ans.at(buf)++;
            }
        }
    }

    for(int i=1; i<=N; i++) cout << ans.at(i) << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <vector>

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

using namespace std;

int N, M;
int A[1000001];
int B[1000001];

int main() {
  scanf("%d %d", &N, &M);
  REP(i, N)
  scanf("%d ", &A[i]);
  REP(i, M)
  scanf("%d ", &B[i]);
  sort(A, A + N);
  sort(B, B + M);
  long long int mod = 1000000007;

  // check whether duplicate number exists.
  bool flag = false;
  REP(i, N - 1) {
    if (A[i] == A[i + 1])
      flag = true;
  }
  REP(i, M - 1) {
    if (B[i] == B[i + 1])
      flag = true;
  }
  if (flag) {
    cout << 0 << endl;
    return 0;
  } else {
    // check whether A[i] or B[i] exists.
    bool row[1000001];
    bool col[1000001];
    REP(i, 1000001) {
      row[i] = false;
      col[i] = false;
    }
    REP(i, N)
      row[A[i]] = true;
    REP(i, M)
      col[B[i]] = true;

    // Count
    int mul = N * M;
    long long int ans = 1;
    for (int i = mul; i > 0; i--) {
      auto ita = lower_bound(A, A + N, i);
      auto itb = lower_bound(B, B + M, i);
      if (row[i] && col[i]) {
        continue;
      } else if (!row[i] && col[i]) {
        ans *= (N - distance(A, ita));
        ans %= mod;
      } else if (row[i] && !col[i]) {
        ans *= (M - distance(B, itb));
        ans %= mod;
      } else {
        ans *= (N - distance(A, ita)) * (M - distance(B, itb)) - (mul - i);
        ans %= mod;
      }
    }
    cout << ans << endl;
    return 0;
  }
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;

typedef long long ll;

ll gcd(ll c, ll d) {
	ll e = c % d;
	if (e == 0) return d;
	return gcd(d, e);
}

int main() {

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	a--;

	ll f, g, h;
	ll e;
	if (c < d) {
		e = gcd(d, c);
	}
	else {
		e = gcd(c, d);
	}
	e = c * d / e;
	f = ll(b / c) - ll(a / c);
	g = ll(b / d) - ll(a / d);
	h = ll(b / e) - ll(a / e);
	cout << b - a - (f + g - h) << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
ok = 1
for i in range(len(S)):
    if i % 2 == 1 and S[i] not in ['L', 'U', 'D']:
        ok = 0
    if i % 2 == 0 and S[i] not in ['R', 'U', 'D']:
        ok = 0
print('Yes' if ok else 'No')


Measured memory_bytes: 9020
/**
 *    Author:  "Robin Singh" !!!
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     // 0 -> n-1 (i,0,n)
#define bk(i, j, k) for(int i = j-1; i >= k; i--)  // n-1 -> 0 (i,n,0)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0
#define rtn return 
#define nl "\n"      // avoid endl
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const ld eps = 1e-9;
const ll INF = (1LL<<61);
const int inf = (1<<30);
//-------------------------------------------------------------------------------------------------------------
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//-------------------------------------------------------------------------------------------------------------

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    ll a[n];
    ll t = 0, ans = INF;
    vll pos, neg;
    
    fr(i, 0, n){
        cin >> a[i];
        if(a[i] == 0) k--;
        else if(a[i] > 0) pos.pb(a[i]);
        else neg.pb(-a[i]);
    }
    if(k == 0){ 
        cout << 0;
        rtn 0;
    }
    
    if(szz(neg) > 0) reverse(all(neg));
    if(szz(pos) >= k) ans = pos[k-1];
    if(szz(neg) >= k) ans = min(ans, neg[k-1]);

    if(szz(pos) == 0 || szz(neg) == 0){
        cout << ans;
        rtn 0;
    }
  //  dbg(ans);
    ll cur = 0;
    for(int i=0; i<szz(pos); i++){
        cur = pos[i];
        t = cur;
        if(szz(neg) > k-i-2){
        t += neg[k-i-2];
        t += cur;
        ans = min(ans, t);
        }
      //  dbg(i, t);
    }
    cur = 0;
    for(int i=0; i<szz(neg); i++){
        cur = neg[i];
        t = cur;
        if(szz(pos) > k-i-2){
        t += pos[k-i-2];
        t += cur;
        ans = min(ans, t);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 2424
N, M, R = map(int, input().split())
RL = [int(x) for x in input().split()]

import heapq
def dijkstra(adj, n, st=1):
    dj = [2**64] * (n + 1)
    dj[st] = 0
    q = []
    heapq.heappush(q, (0, st))
    while q:
        fc, fn = heapq.heappop(q)
        if dj[fn] < fc: continue
        for tn, lc in adj[fn]:
            if dj[fn] + lc < dj[tn]:
                dj[tn] = dj[fn] + lc
                heapq.heappush(q, (dj[tn], tn))
    return dj

adj = dict((x, []) for x in range(N + 1))
for _ in range(M):
    a, b, c = map(int, input().split())
    adj[a].append((b, c))
    adj[b].append((a, c))

costs = [None] * len(RL)
for i, r in enumerate(RL):
    costs[i] =  dijkstra(adj, N, r)

import functools
@functools.lru_cache(maxsize=None)
def f(last, cost, left):
    if not left: return cost
    ret = float('inf')
    for i, x in enumerate(left):
        ret = min(ret, f(x, cost + costs[RL.index(last)][x], left[:i] + left[i+1:]))
    return ret

print(min(f(x, 0, tuple(set(RL) - set([x]))) for x in RL))

Measured memory_bytes: 38864
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	ll n;
	cin>>n;
	ll a[n+5];
	map<ll,ll> b;
	rep(i,n)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	ll ans=0;
	for(auto raj:b)
	{
		ll temp;
		temp=raj.second;
		ans+=(temp*(temp-1))/2;	
	}

	rep(i,n)
	{
		ll dp;
		ll raj=b[a[i]];
		dp=ans- (raj*(raj-1))/2 + ((raj-1)*(raj-2))/2; 
		cout<<dp<<endl;
	}
	return 0;
}


Measured memory_bytes: 11136
#include <cstdio>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

constexpr int MAX_N = 100000;

ll N, M;
ll A[MAX_N+10], S[MAX_N+10];
std::map<ll, ll> cnt;
ll ans;

int main()
{
  scanf( "%lld%lld", &N, &M );
  rep( i, N )
    scanf( "%lld", A+i ), S[i+1] = S[i]+A[i], ++cnt[S[i+1]%M];

  for( auto it = cnt.begin(); it != cnt.end(); ++it )
    ans += (it->second*(it->second-1))/2 + (it->first ? 0 : it->second);

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

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

#define i64 long long int

int n;
i64 k;
vector<int> pos, neg;
int zero;

i64 n2(int x) {
	return 1LL*x*(x-1)/2;
}

// count of a[i]*b[j]>=val
i64 calc(i64 val, vector<int> &a, vector<int> &b) {
	int na = a.size(), nb = b.size();
	int ita, itb = 0;
	i64 res = 0LL;
	for(ita = na-1;ita>=0;ita--) {
		while(itb<nb && 1LL*a[ita]*b[itb]<val) itb++;
		res += nb-itb;
	}
	//cout<<val<<' '<<res<<endl;
	return res;
}
// count of a[i]*a[j]>=val, i!=j
i64 calc2(i64 val, vector<int> &a) {
	int na = a.size();
	int l = 0;
	i64 res = 0LL;
	for(int r = na-1;r>=0;r--) {
		while(l<r && 1LL*a[l]*a[r]<val) l++;
		if(l>=r) break;
		res += r-l;
	}
	//cout<<val<<' '<<res<<endl;
	return res;
}

int main() {
	scanf("%d%lld", &n, &k);
	pos.clear(); neg.clear();
	for(int i=0;i<n;i++) {
		int x;
		scanf("%d", &x);
		if(x<0) neg.push_back(-x);
		else 
		if(x>0) pos.push_back(x);
		else zero++;
	}
	sort(neg.begin(), neg.end());
	sort(pos.begin(), pos.end());
	
	bool fpos;
	if(k<=1LL*neg.size()*pos.size()) {
		fpos = false;
	} else
	if(k>=n2(n) - n2(pos.size()) - n2(neg.size())) {
		fpos = true;
		k = n2(n) - k + 1;
	} else {
		puts("0");
		return 0;
	}
	
	i64 l = 1LL, r = 1e18, ans = 0LL;
	while(l<=r) {
		i64 mi = (l+r)/2;
		
		if(!fpos) {
			if(calc(mi, neg, pos) >= k) {
				ans = mi;
				l = mi+1;
			} else {
				r = mi-1;
			}
		} else {
			if(calc2(mi, neg) + calc2(mi, pos) >= k) {
				ans = mi;
				l = mi+1;
			} else {
				r = mi-1;
			}
		}
	}
	if(!fpos) ans*=-1;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e5+5;
ll n,h[MAXN];
void solve()
{
    ll pre=0;
    for(ll i=1;i<=n;i++)
    {
        ll x=h[i];
        if(x<pre)
        {
            printf("No\n");
            return;
        }
        else
        {
            if(x-1>=pre)
            {
                x--;
            }
            pre=x;
        }
    }
    printf("Yes\n");
}
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld",&h[i]);
    }
    solve();
}


Measured memory_bytes: 1024
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;



int main(){
    int n,q,a;
    deque<int> S;
    deque<int> T;
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> a;
        S.push_back(a);
    }
    cin >> q;
    for (int i = 0; i < q ; ++i) {
        cin >> a;
        T.push_back(a);
    }

    int count = 0;
    for (int i = 0; i < q ; ++i) {
        if(binary_search(S.begin(),S.end(),T[i])){
         count ++;
        }
    }
    cout << count << endl;
    return 0;
}

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

int dp[50];

int fib(int n) {
  if (n == 0 || n == 1) {
    return 1;
  } else if (dp[n] != -1) {
    return dp[n];
  } else {
    return fib(n - 1) + fib(n - 2);
  }
}

int main() {
  int n;
  cin >> n;
  int F[50];
  F[0] = F[1] = 1;
  for (int i = 2; i < 50; i++) F[i] = F[i - 1] + F[i - 2];
  int ans = fib(n);
  cout << F[n] << endl;
  return 0;
}


Measured memory_bytes: 3120
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	long int N, M;
	cin >> N >> M;
	if (N > M/2) {
		cout << M/2 << endl;
	} else {
		long int S = N;
		M -= N*2;
		cout << S+M/4 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
  int ver[200][200];
  int i,j,a,deg,num,n;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
    {
      ver[i][j] = 0;
    }
    }
 
  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&a,&deg);
      for(j=1;j<=deg;j++)
    {
      scanf("%d",&num);
      ver[i][num] = 1;
    }
    }
 
  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
    {
      if(j == n)printf("%d",ver[i][j]);
      else printf("%d ",ver[i][j]);
    }
      printf("\n");
    }
 
  return 0;
}

Measured memory_bytes: 684
n = int(input())
A = list(map(int, input().split()))
ans = 1
flag = True
if 0 in A:
  print(0)
  flag = False
if flag:
  for i in range(n):
    ans *= A[i]
    if ans > 10**18:
      print(-1)
      flag = False

      break
  if flag:
    print(ans)

Measured memory_bytes: 21784
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll X;
  cin >> X;
  vll M(1, 1);

  ll ans = 1;
  REP(j, 2, 33) {
    REP(k, 2, 33) {
      ll p = pow(j, k);
      if (p <= X && ans < p) {
        ans = p;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	 public static void main(String[] args) {
	     Scanner sc = new Scanner(System.in);
		 while(true){
			 int x = sc.nextInt();
			 int y = sc.nextInt();
			 if ( x == 0 && y == 0) break;
			 if (x < y) {
				 System.out.println(String.format("%d %d",x,y));
			 }else {
				 System.out.println(String.format("%d %d",y,x));
			 }
		 }
	 }
	
}



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

int c[16], x[20001];
int dp[20001][256];
int diff(int i, int a) {
	return (x[i] - a)*(x[i] - a);
}
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		rep(i, m)scanf("%d", &c[i]);
		rep(i, n)scanf("%d", &x[i]);
		memset(dp, 0x3f, sizeof(dp));
		dp[0][128] = 0;
		rep(i, n)rep(j, 256) {
			if (dp[i][j] == INF)continue;
			rep(k, m) {
				int a = min(255, max(0, j + c[k]));
				dp[i + 1][a] = min(dp[i + 1][a], dp[i][j] + diff(i, a));
			}
		}
		int Min = INF;
		rep(j, 256)Min = min(Min, dp[n][j]);
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 23256
#include<bits/stdc++.h>
using namespace std;
int n;
double prob[3005];

void solve(){
	vector<vector<double>> dp(n+1,vector<double>(n+1));
	dp[0][0]=1.0;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=(1.0-prob[i-1])*dp[i-1][0];
	}
	for(int j=1;j<=n;j++)dp[0][j]=0.0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=(prob[i-1]*dp[i-1][j-1])+((1.0-prob[i-1])*dp[i-1][j]);
		}
	}
	double res=0.0;
	for(int i=n/2+1;i<=n;i++)
		res+=dp[n][i];
	cout<<setprecision(10)<<res<<endl;
}
int main(){
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>prob[i];

	solve();
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  long long t, a;
  cin>>t>>a;
  for (int i=1; i<n; i++) {
    long long ti, ai;
    cin>>ti>>ai;
    long long x = max((t - 1) / ti + 1, (a - 1) / ai + 1);
    t = ti * x;
    a = ai * x;
  }
  cout<<t + a<<endl;
}

Measured memory_bytes: 256
S = input()
lenS = len(S)
bcnt = S.count('B')
wcnt = lenS - bcnt
if bcnt > wcnt:
    ms = 'W'
    rc = wcnt
else:
    ms = 'B'
    rc = bcnt
sum = 0

for i, s in enumerate(S):
    if rc == 0:
        break
    if s == ms:
        if ms == 'W':
            sum += i-rc+1
        elif ms == 'B':
            sum += lenS-i-rc
        rc -= 1
print(sum)

Measured memory_bytes: 9272
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int o=0;
    double d=0.0,w=2147483648.0;
    for(int i=0;i<8;i++)w/=2;
    string s;
    cin>>s;
    for(int i=0;i<8;i++){
      int p;
      if(s[i]>='0'&&s[i]<='9')p=s[i]-'0';
      else p=s[i]-'a'+10;
      int ss[4]={};
      for(int j=3;j>=0;j--)ss[j]=(p>>j)&1;
      for(int j=3;j>=0;j--){//cout<<w<<endl;
	if(!i&&j==3){if(ss[j])o++;}
	else{
	  if(ss[j])d+=w;
	  w/=2.0;
	  if(w==0)w=0.5;//cout<<w<<endl;
	}
      }
    }
    if(o)cout<<'-';
    if(d-(long int)d){
      printf("%.99g\n",d);
    }
    else{
      printf("%ld",(long int)d);cout<<".0"<<endl;
    }
   }
}

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

int main() {
	int x, y, z, k; cin >> x >> y >> z >> k;
	vector<ll> a(x), b(y), c(z);
	for (int i = 0; i < x; ++i) cin >> a[i];
	for (int i = 0; i < y; ++i) cin >> b[i];
	for (int i = 0; i < z; ++i) cin >> c[i];
	vector<ll> ab;
	for (int i = 0; i < x; ++i)	for (int j = 0; j < y; ++j) ab.push_back(a[i]+b[j]);
	sort(ab.begin(), ab.end(), greater<ll>());
	vector<ll> abc;
	for (int i = 0; i < min(k, x*y); ++i) for (int j = 0; j < z; ++j) abc.push_back(ab[i]+c[j]);
	sort(abc.begin(), abc.end(), greater<ll>());
	for (int i = 0; i < k; ++i) cout << abc[i] << endl;
	return 0;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buff = null;
		buff = new BufferedReader(new InputStreamReader(System.in));

		String line = buff.readLine();
		int count = 0;
		for(int i = 0; i < 3; ++i){
			if(line.charAt(i) == '1'){
				count++;
			}
		}
		System.out.println(count);
	}

	static long f() {
		long ans = 0;


		return ans;
	}
}

Measured memory_bytes: 19796
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N = readint()[1]
  H = readint()

  s = 0
  for i in 2:N
    if H[i] - H[i-1] <= 0
      s += H[i] - H[i-1]
    else
      s = 0
    end

    if s <= -2 || H[i] - H[i-1] <=-2
      println("No")
      return
    end
  end
  println("Yes")
  return

end



main()

Measured memory_bytes: 198740