akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std;

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node *find( Node *u, int k )
{
    while( u != NIL && k != u->key ){
        if( k< u->key )
            u = u->left;
        else
            u = u->right;
    }
    return u;
}

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));

    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while( x!=NIL ){
        y = x;
        if( z->key < x->key ){
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if ( y ==NIL ){
        root = z;
    } else {
        if( z->key < y->key ){
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder( Node *u )
{
    if( u==NIL )
        return;
    inorder(u->left);
    printf( " %d", u->key );
    inorder(u->right);
}

void preorder( Node *u )
{
    if( u==NIL )
        return;
    printf( " %d", u->key );
    preorder( u->left );
    preorder( u->right );
}

int main()
{
    int n, i, x;
    string com;

    scanf( "%d", &n );

    for( i=0; i<n; i++ ){
        cin >> com;

        if( com == "insert" ){
            scanf( "%d", &x );
            insert(x);
        } else if ( com == "print" ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if( com == "find" ){
            scanf("%d", &x);
            Node *t = find(root,x);
            if( t!=NIL )
                cout << "yes\n";
            else
                cout << "no\n";
        }
    }
    return 0;
}



Measured memory_bytes: 21928
#include <iostream>
#include <cmath>
#include <complex>
#include <tuple>
#include <vector>
using namespace std;

using vec = complex<double>;
using line = pair<vec,vec>;
using polygon = vector<vec>;
const double eps = 0.0000001;

double inner_product(vec u,vec v){
    return real(u*conj(v));
}
double cross_product(vec u,vec v){
    return imag(conj(u)*v);
}

vec projection(line l,vec p){//p???l???????°???±
    vec s=l.first, t=l.second;
    double k = inner_product(t-s,p-s)/inner_product(t-s,t-s);
    return (1.0-k)*s+k*t;
}

vec reflection(line l,vec p){
    return 2.0*projection(l,p)-p;
}

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = cross_product(ab,ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(inner_product(ab,ac)<0){
        return 2; //C-A-B
    }else{
        if(inner_product(ab,ab)<inner_product(ac,ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

bool isIntersect(line l0, line l1){
    int s = ccw(l0.first,l0.second,l1.first)*ccw(l0.first,l0.second,l1.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    s=ccw(l1.first,l1.second,l0.first)*ccw(l1.first,l1.second,l0.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    else return true;
}

vec interSection(line l0, line l1){
    vec s0, t0, s1, t1;
    tie(s0,t0)=l0; tie(s1,t1)=l1;
    double k = cross_product(t1-s1,s1-s0)/cross_product(t1-s1,t0-s0);
    return s0+(t0-s0)*k;
}

double segLength(line l){
    return abs(l.first-l.second);
}

double distLine2point(line l, vec p){
    return abs(cross_product(l.second-l.first,p-l.first))/abs(l.second-l.first);
}

double distSeg2Point(line l, vec p){
    vec x = projection(l,p);
    double L = segLength(l);
    if(abs(x-l.first)<L&&abs(x-l.second)<L){
        return abs(x-p);
    }else{
        return min(abs(l.first-p),abs(l.second-p));
    }
}

double distSeg2Seg(line l1, line l2){
    if(isIntersect(l1,l2)) return 0;
    double ret = 1e20;
    ret = min(ret,distSeg2Point(l1,l2.first));
    ret = min(ret,distSeg2Point(l1,l2.second));
    swap(l1,l2);
    ret = min(ret,distSeg2Point(l1,l2.first));
    ret = min(ret,distSeg2Point(l1,l2.second));
    return ret;
}

double area(polygon& g){
    double S=0;
    int n=g.size();
    for(int i=0;i<n;i++){
        S+=cross_product(g[i],g[(i+1)%n]);
    }
    S/=2;
    return S;
}

//???????????§???????????????


int main(){
    int n;
    cin >> n;
    polygon g;
    while(n--){
        int x,y;
        cin>>x>>y;
        g.emplace_back(x,y);
    }
    g.push_back(g.front());
    cout.precision(1);
    cout << fixed;
    cout << area(g) << endl;
    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

const int INF = 1 << 30;

int main() {
  in(int, x, n);
  if (n == 0) {
    out(x);
    return 0;
  }
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(all(p));
  int mi = p[0], ma = p[n-1];
  set<int> sp(all(p));
  int mindiff = INF;
  int ans;
  for (int m = mi - 1; m <= ma + 1; ++m) {
    if (sp.count(m)) continue;
    if (abs(x - m) < mindiff) {
      mindiff = abs(x - m);
      ans = m;
    }
  }
  out(ans);
}


Measured memory_bytes: 3628
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve()
{
    ll vis[110]={0};
    ll n,k;cin>>n>>k;
    for(ll i=1;i<=k;i++)
    {
        ll d;cin>>d;
        for(ll j=1;j<=d;j++)
        {
            ll x;cin>>x;
            vis[x]++;
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
        if(vis[i]==0)ans++;
    cout<<ans<<endl;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3656
'use strict';

const main = input => {
  input = input.split('\n');
  const n = Number(input[0]);
  const A = input[1].split(' ').map(Number);
  const q = input[2].split(' ').map(Number);
  const mList = input[3].split(' ').map(Number);

  for (let i = 0; i < q; ++i) {
    solve(0, mList[i]) ? console.log('yes') : console.log('no');
  }

  function solve(i, m) {
    if (m === 0) {
      return true;
    }
    if (i >= n) {
      return false;
    }
    return solve(i + 1, m) || solve(i + 1, m - A[i]);
  }
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

// const S = [];
// function makeCombination(n) {
//   for (let i = 0; i < n; ++i) {
//     S[i] = 0;
//   }
//   rec(0, n);
// }
// function rec(i, n) {
//   if (i === n) {
//     console.log(S);
//     return;
//   }
//   S[i] = 0;
//   rec(i + 1, n);
//   S[i] = 1;
//   rec(i + 1, n);
// }
// makeCombination(3);



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

vector<vector<int>> t;
int n, a[222222], L[222222], l[222222];
void g(int u, int v) {
    auto it = lower_bound(l, l + n, a[v]);
    swap(*it, a[v]);
    L[v] = lower_bound(l, l + n, 1e9 + 1) - l;
    for(int w : t[v])
        if(u != w)
            g(v, w);
    *it = a[v];
}
int main() {
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i + 1];
    t.resize(n + 1);
    for(int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        t[u].push_back(v);
        t[v].push_back(u);
    }
    fill(l, l + n + 1, 2e9);
    g(0, 1);
    for(int i = 0; i < n; i++)
        cout << L[i + 1] << '\n';
    return 0;
}


Measured memory_bytes: 30888
#include<stdio.h>
int main()
{
    int a,b,c,m,t=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)
        m=a,a=b,b=m;
    if(a>c)
        m=a,a=c,c=m;
    if(b>c)
        m=b,b=c,c=m;
    t+=(b-a)/2;
    a+=(b-a)/2*2;
    t+=c-a;
    t+=b-a;
    printf("%d\n",t);
    return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
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;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    int X,A,B; cin>>X>>A>>B;
    cout << (X-A)%B << endl;
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    ll res = (n + 1) * n / 2;
    res -= n;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #pragma GCC optimization ("O3,unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
using namespace std;

#define _ << ": " <<
#define watch1(var1) (cerr << (#var1) _ var1 << '\n')
#define watch2(var1, var2) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << '\n'
#define watch3(var1, var2, var3) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << ", " << (#var3) _ var3 << '\n'
#define wloop(size, arr) cerr << (#arr) << ": "; for (int i = 0; i < size; i++) cerr << arr[i] << " \n"[i+1 == size]

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define ints(a...) int a; read(a)
#define longs(a...) int64_t a; read(a)
#define IN(a) for (auto &it : a) cin >> it

void solve() {
    ints(x, n);
    set<int> v;
    for (int i = 0; i < n; i++) {
        ints(x);
        v.insert(x);
    }
    int dist = INT_MAX, ans = 0;
    for (int i = 0; i < 102; i++) {
        if (v.count(i) == 0 && dist > abs(x - i)) {
            dist = abs(x - i);
            ans = i;
        }
    }
    show(ans);
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1; 
    // cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
	long long a,b,c,k;
	cin >> a >> b >> c >> k;
	long long ans=(k%2==0?1:-1)*(a-b);
	if(-1000000000000000000<=ans&&ans<=1000000000000000000){
		cout << ans << endl;
	}else {
		cout << "Unfair" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

void print_list(int* a, int n){
  for(int i = 0; i < n - 1; i++){
    std::cout << a[i] << " ";
  }
  std::cout << a[n - 1] << std::endl;
}

void bubbleSort(int* a, int n){
  bool sorted = false;
  int swap_count = 0;
  while(!sorted){
    sorted = true;
    for(int i = n - 1; i > 0; i--){
      if(a[i] < a[i - 1]){
	int t = a[i]; a[i] = a[i - 1]; a[i - 1] = t;
	sorted = false;
	swap_count++;
      }
    }
  }
  print_list(a, n);
  std::cout << swap_count << std::endl;
}

int main(){
  int n;
  std::cin >> n;

  int a[n];
  for(int i = 0; i < n; i++){
    std::cin >> a[i];
  }
  
  bubbleSort(a, n);
 
  return 0;
}



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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

li n, k;
li a[100100];

li all_sum[100100];
li plus_sum[100100];

int main(void)
{
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
	}
	all_sum[0] = 0;
	plus_sum[0] = 0;
	rep(i, n) {
		all_sum[i + 1] = all_sum[i] + a[i];
		plus_sum[i + 1] = plus_sum[i];
		if (a[i] > 0) {
			plus_sum[i + 1] += a[i];
		}
	}

	li res = 0;
	rep(i, n - k + 1) {
		res = max(res, max(0ll, all_sum[i + k] - all_sum[i])
		          + plus_sum[n] - plus_sum[i + k] + plus_sum[i]);
	}
	cout << res << endl;


	return 0;
}

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

using namespace std;

long get_cost(int n, vector<int>& v) {
    long ret = 0;
    for (auto i : v) {
        ret += (n - i) * (n - i);
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<int> v;
    for (int i = 0; i < N; ++i) {
        int num;
        cin >> num;
        v.push_back(num);
    }

    int min = *min_element(v.begin(), v.end());
    int max = *max_element(v.begin(), v.end());

    long min_cost = INT_MAX;

    for (int j = min; j <= max; ++j) {
        long new_cost = get_cost(j, v);
        if (new_cost < min_cost) {
            min_cost = new_cost;
        }
    }

    cout << min_cost << endl;

    return 0;
}

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

int main(){
  double N; cin>>N;
  cout << fixed << setprecision(10);
  if(N==1)cout<<N<<endl;
  else if(fmod(N,2)==0)cout<<(N/2)/N<<endl;
  else if(fmod(N,2)!=0)cout<<((N+1)/2)/N<<endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    ll n,k;
    cin>>n>>k;

    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ll first=i*(i-1)/2;
        ll final=(n*2-i+1)*i/2;
        ll add=final-first+1;
        ans=(ans+add)%MOD;
    }

    cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;

const int N = 2e5 + 5;

int arr[N];
int n;

ll get_min(int b) {
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        res += abs(arr[i] - b);
    }
    return res;
}

int solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &arr[i]);
        arr[i] -= i + 1;
    }
    int l = -1e9, r = 1e9;
    while (r - l > 2) {
        int ml = l + (r - l) / 3;
        int mr = r - (r - l) / 3;
        if (get_min(ml) < get_min(mr)) {
            r = mr;
        } else {
            l = ml;
        }
    }
    cout << min(get_min(l + 1), min(get_min(l), get_min(r))) << endl;


    return 0;
}

int main() {
#ifdef LOCALHOST
    freopen("input", "r", stdin);
#endif
    while (solve());

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if((b - a) % 2 == 0) {
        cout << (b - a) / 2 << endl;
    } else {
        ll ans1 = 0, ans2 = 0;
        ans1 = a + (b - a - 1) / 2;
        ans2 = (n - b + 1) + (b - a - 1) / 2;
        cout << min(ans1, ans2) << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  string n;
  rep(i,3){
  cin >> n;
    cout << n[i];
  }
  cout << "\n";

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N;
    
    cin >> N;
    
    vector<int> d(N);
    for (int i=0;i<N;i++){
        cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    
    if(d.size()%2==0){
        int a = d.at(d.size()/2-1);
        int b = d.at(d.size()/2);
        cout << b-a << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MAXW 100001
#define INF lint_MAX
#define lint long long int
using namespace std;

lint n, w, v, p, maior;
lint dp[MAXW];

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> w;
    
    for(lint i = 0; i <= w; i++){
    	dp[i] = 0;
    }
    
    cin >> p >> v;
    
    for(lint i = p; i <= w; i++){
    	dp[i] = v;
    }
    
    for(lint i = 1; i < n; i++){
    	cin >> p >> v;
    	for(lint j = w; j >= p; j--){
    		lint z = j - p;
    		dp[j] = max(dp[z] + v, dp[j]);
    	}
    }
    
    /*maior = 0;
    for(lint i = 0; i <= w; i++){
    	maior = max(maior,dp[i]);
    }*/
    
    cout << dp[w] << '\n';
    
    return 0;
}


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

using namespace std;

int main(){
  int a,b,c; cin >> a >> b >> c;
  int maxi=max({a,b,c});
  if(maxi==a) cout << 'A';
  else if(maxi==b) cout << 'B';
  else cout << 'C';
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

constexpr lint INF = 1e17;
int main()
{
    int N;
    cin >> N;
    vector<plint> LR(N);
    REP(i, N) cin >> LR[i].first >> LR[i].second;
    sort(LR.begin(), LR.end(), [](plint l, plint r) { return l.first + l.second > r.first + r.second; });

    vector<plint> w(N, plint(N / 2, N / 2));
    REP(i, N / 2)
    {
        w[i] = make_pair(i, i + 1);
        w[N - 1 - i] = make_pair(i + 1, i);
    }
    vector<lint> dp(N + 1, INF);
    dp[0] = 0;
    REP(i, N)
    {
        vector<lint> dp_new(N + 1, INF);
        REP(j, i + 1)
        {
            mmin(dp_new[j + 1], dp[j] + LR[i].first * w[j].first + LR[i].second * w[j].second);
            mmin(dp_new[j], dp[j] + LR[i].first * w[N - 1 - i + j].first + LR[i].second * w[N - 1 - i + j].second);
        }
        dp = dp_new;
    }
    cout << *min_element(dp.begin(), dp.end()) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int main()
{
    int a =D(),b=D();
    string s;
    cin>>s;
    if(s[a]!='-'){
        cout<<"No"<<endl;
        return 0;
    }
 int c=0;
 for(int i=0;i<a+b+1;++i)
  {
    if(s[i]=='-')
        c++;
    if(!(isdigit(s[i]))&&s[i]!='-'){
        cout<<"No"<<endl;
        return 0;
    }
  }
  if(c>1)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int m,d;
	scanf("%d%d",&m,&d);
	if(m<4||d<22) {
		printf("0\n");
		return 0;
	}
	int ans=0;
	for(int i=4;i<=m;i++)
		for(int j=2;j<=d/10;j++)
			for(int k=2;k<=9;k++)
				if(j*k==i&&j*10+k<=d) {
					ans++;
					break;
				}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
main=getLine>>=putStrLn.f
 where l = ['a'..'z']
       f (a:b:s)=if a=='A'&&(elem b l)&&(elem (last s) l) then (g (init s) False) else "WA"
       g [] t = if t then "AC" else "WA"
       g (x:s) t |t =if (elem x l) then (g s t) else "WA"
                 |x=='C' =g s True
                 |elem x l =g s t
                 |otherwise ="WA"

Measured memory_bytes: 380
#include<bits/stdc++.h>
#define li long long 
using namespace std ; 
int main(){
	int n ; 
	cin>> n ; 
   map<string , int> m ; 
   for(int i = 0 ; i < n ; ++i ){
	   string s ; 
	   cin>> s ; 
	   m[s]++ ; 
   }
   int max = 0 ; 
   for(auto it = m.begin() ; it != m.end() ; ++it){
	   if(it->second > max)
	   max = it->second ; 
   }
   for(auto it = m.begin() ; it != m.end() ; ++it){
	    if(it->second == max){
			cout<<it->first<<endl;
		}
	}
}


Measured memory_bytes: 25216
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

int main() {
  //
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  multiset<ll> s;
  s.insert(a[n - 1]);
  for (int i = n - 2; i >= 0; i--) {
    multiset<ll>::iterator it = s.upper_bound(a[i]);
    if (it == s.end()) {
      s.insert(a[i]);
    } else {
      // cout << a[i] << "<" << *it << endl;
      s.erase(it);
      s.insert(a[i]);
    }
  }
  cout << s.size() << endl;
  return 0;
}


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

using namespace std;

class HASH {
    int mod, base;
    vector<int> p = {1} , hashes = {0};

    int mul(int a , int b) {
        return a * 1ll * b % mod;
    }

    int add(int a , int b) {
        a += b;
        while (a >= mod) a -= mod;
        while (a < 0) a += mod;
        return a;
    }

public:
    HASH(int _mod , int _base) : mod(_mod), base(_base) {}

    void push_back(int x) {
        hashes.push_back(add(mul(hashes.back() , base) , x));
        p.push_back(mul(p.back() , base));
    }

    int get(int l , int r) {
        assert(r + 1 < hashes.size());
        return add(hashes[r + 1] , -mul(p[r - l + 1] , hashes[l]));
    }
};

struct D_HASH {
    const int B1 = 256;
    const int B2 = 128;
    const int M1 = 2000000011;
    const int M2 = 1000000007;

    array<HASH , 2> h;
    D_HASH() : h{HASH(M1 , B1) , HASH(M2 , B2)} {}


    void push_back(int x) { // x != 0
        h[0].push_back(x);
        h[1].push_back(x);
    }

    array<int , 2> get(int l , int r) { // send zero based
        assert(l <= r);
        return {h[0].get(l , r) , h[1].get(l , r)};
    };
};


int n;
bool good(int len , D_HASH &dh) {
    map<array<int , 2> , int> exist;
    vector<array<int , 2> > v(n);

    for (int i = 0 ;i + len - 1 < n ;i++)
        v[i] = dh.get(i , i + len - 1);

    for (int i = len ;i + len - 1 < n ;i++)
        exist[v[i]]++;

    if (exist[v[0]])
        return 1;

    int r = len;
    while (r < n) {
        exist[v[r]]--;
        if (exist[v[r - len + 1]])
            return 1;
        r++;
    }

    return 0;
}

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
   
    string s;
    cin >> n >> s;

    D_HASH dh;
    for (char &c : s)
        dh.push_back(c);

    int l = 1 , r = n , ans = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (good(mid , dh)) {
            ans = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }

    cout << ans;
}

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

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T int t;cin>>t;rep(i,t)



void solve() {

    int n;
    cin >> n;
    string str;
    cin >> str;
    int count = 0, i = 0, j = n - 1;

    while (i < j) {
        if (str[i] == 'R')
            i++;
        else if (str[j] == 'W')
            j--;
        else {
            count++;
            i++;
            j--;
        }
    }

    cout << count << "\n";
    
 }

int main()
{
    fastio;
    // T
    solve();
    //code
    return 0;
}


Measured memory_bytes: 3772
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define M 1000001
vector<bool> dp(M, true);

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    sort(all(A));

    int pre_div = 0;
    rep(i, N){
        int div = A[i];
        if(pre_div==div) dp[div] = false;
        else{
            int n = div;
            while(true){
                n += div;
                if(n >= M) break;
                dp[n] = false;
            }
        }
        pre_div = div;
    }

    int ret = 0;
    rep(i, N) if(dp[A[i]]) ret++;
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 4260
#include <iostream>

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if ((A + B) >= C) {
        // 解毒たっぷりあるのでCは全部食べれるはず
        cout << (B + C) << endl;
    } else {
        // 解毒足りないので C は (A + B) + 1 しかだめ
        cout << (B + ((A + B) + 1)) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int H,W;
   while(1){
    cin >> H >> W;
    if(H == 0 && W == 0)
       break;
    int i = 0;
    int j = 0;
    for(i = 0; i < H; i++){
        for(j = 0; j < W; j++){
            cout << "#";
            }
        cout << endl;
       }
       cout << endl;
    }
   return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>
  #include<stdlib.h>
  #define NIL NULL
  struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
  };
  typedef struct node * Node;


  Node root;

  Node treeMinimum(Node x){
    while(x->left != NIL)
      x = x->left;
      return x;
  }

  Node treeMaximum(Node x){
    while(x->right != NIL)
      x = x->right;

    return x;
  }

  Node treeSearch(Node x, int k){
    if(x == NIL && k == x->key) return x;
    if(k < x->key) return treeSearch(x->left,k);
    else return treeSearch(x->right,k);
  }

  Node treeSuccessor(Node x){
    Node y;

    if(x->right != NIL) return treeMinimum(x->right);
    y = x->parent;
    while(y != NIL && x == y->right){
      x = y;
      y = y->parent;
    }
    return y;
  }

  void treeDelete(Node z){
    Node y; // node to be deleted
    Node x; // child of y

    if(z->left == NIL || z->right == NIL)
      y = z;
    else
      y = treeSuccessor(z);

    if(y->left != NIL)
      x = y->right;
    else
      x = y->right;

    if(x != NIL)
      x->parent = y->parent;

    if(y->parent == NIL)
      root = x;
    else if(y == y->parent->left)
      y->parent->left = x;
    else
      y->parent->right = x;

    if(y != z)
      z->key = y->key;
  }

  void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!=NIL){
      y = x;
      if(z->key < x->key) x=x->left;
      else x=x->right;
    }
    z->parent = y;

    if(y==NIL)root=z;
    else
      if(z->key < y->key) y->left=z;
      else y->right=z;
  }

  void inorder(Node x){
    if(x != NIL){
      inorder(x->left);
      printf(" %d",x->key);
      inorder(x->right);
    }
  }

  void preorder(Node x){
    if(x != NIL){
      printf(" %d",x->key);
      preorder(x->left);
      preorder(x->right);
    }
  }


  int main(void){
    int n, i, x;
    char C[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
      scanf("%s", C);
      if ( C[0] == 'f' ){
        scanf("%d", &x);
        Node t = treeSearch(root, x);
        if (t!=NIL) printf("yes\n");
        else printf("no\n");
      } else if (C[0] =='i'){
        scanf("%d", &x);
        insert(x);
      } else if (C[0] =='p'){
        inorder(root);
        printf("\n");
        preorder(root);
        printf("\n");
      } else if (C[0] =='d'){
        scanf("%d", &x);
        treeDelete(treeSearch(root, x));
      }
    }
    return 0;
  }



Measured memory_bytes: 25156
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
void test_case(){
	int d, t, s; cin>>d>>t>>s;
	int dis = s * t;
	if(d <= dis){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}
		
 
signed main(){
	IOS;
	int t=1, i=1; 
	//cin>>t;
	while(t--){
		//cout<<"Case #"<<i<<": ";
		test_case();
		i++;
	}
}


Measured memory_bytes: 3636
def cin; gets.split.map(&:to_i) end
def cout(*x); puts x.join(" ") end

# exit if $0 != __FILE__

n = cin
s = gets.chars
r = s.select{|x|x=='R'}.length
b = s.select{|x|x=='B'}.length

puts r>b ? 'Yes' : 'No'


Measured memory_bytes: 1788
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){


  string s;
  cin >> s;
  
  int ans = 0;
  REP(i,3){
    if(s[i] == '1') ans++;
  }
  
  cout << ans << endl;

 return 0;
}

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

int main()
{
	unsigned long A,B,C,D,Bx,Ax,GCD,i;
	vector<unsigned long> CD={0,0};
	cin>>A>>B>>CD.at(0)>>CD.at(1);
	A-=1;
	C=CD.at(0);
	D=CD.at(1);
	for(i=1;i>0;i++){
		sort(CD.begin(),CD.end());
		if(CD.at(1)%CD.at(0)==0){
			GCD=CD.at(0);
			break;
		}else{
			CD.at(1)-=CD.at(0);
		}
	}
	GCD=C*D/GCD;
	Bx=B-B/C-B/D+B/GCD;
	Ax=A-A/C-A/D+A/GCD;
	cout<<Bx-Ax;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a <= b) {
            System.out.println(a);
            return;
        }
        System.out.println(a - 1);
    }

}


Measured memory_bytes: 21844
n = int(input())
arr = list(map(int ,input().split()))
n_sum = 0
for i in range(n):
        n_sum += arr[i]
n_max = arr[0]
n_min = arr[0]

for i in range(n):
        if n_max < arr[i]:
                n_max = arr[i]
        if n_min > arr[i]:
                n_min = arr[i]

print('%d %d %d' % (n_min, n_max, n_sum))


Measured memory_bytes: 6604
#include <iostream>
using namespace std;
int main(){
    long long a, b, ans;
    cin >> a >> b;
    if(a!=1 && b != 1){
        ans = (a-2) * (b-2);
    }else{
        ans = a * b - 2;
    }
    if(ans<0) ans = 1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//AtCoder ABC121 C - Energy Drink Collector
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N,M; cin>>N>>M;
    vector<pair<ll,ll>> abn(N);
    for(auto&& ab:abn){
        cin>>ab.first>>ab.second;
    }
    sort(abn.begin(),abn.end());
    ll ans=0;
    for(const auto& ab:abn){
        if(M<=0) break;
        ans+=min(M,ab.second)*ab.first;
        M-=ab.second;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1920
import functools
import fractions
N = int(input())
a = list(map(int, input().split()))

L = [0] * N
for i in range(N) :
        if i == 0 :
                L[0] = 0
        elif i == 1 :
                L[1] = a[0]
        else :
                L[i] = fractions.gcd(L[i-1], a[i-1])

a.reverse()
R = [0] * N
for i in range(N) :
        if i == 0 :
                R[0] = 0
        elif i == 1 :
                R[1] = a[0]
        else :
                R[i] = fractions.gcd(R[i-1], a[i-1])
R.reverse()
a.reverse()

gcd = [0] * N
for i in range(N) :
        if i == 0 :
                gcd[0] = R[0]
        elif i == N-1 :
                gcd[N-1] = L[N-1]
        else :
                gcd[i] = fractions.gcd(L[i],R[i])

print(max(gcd))

Measured memory_bytes: 16148
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    A = input([int, 3])
    yesno(22 <= sum(A), "bust", "win")


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
const int N=2000005,MOD=1e9+7,MAX=1e5;

int n,ans;

int  main()
{
        
         scanf("%d",&n);

         for(int i=0;i<n;i++){

           int x;
           scanf("%d",&x);

           ans+=(x-1);
         }
       
       printf("%d\n",ans );
      
 return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.WebSockets;

namespace AtCoderApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var param = new int[input.Length];

            for (int i = 0; i < param.Length; i++)
            {
                param[i] = int.Parse(input[i]);
            }

            while (param[0] > 0 || param[2] > 0)
            {
                param[2] = param[2] - param[1];
                if (param[2] <= 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                param[0] = param[0] - param[3];
                if (param[0] <= 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 27312
#include <cstdio>

using namespace std;

const int MAX_N = 1 << 15;

bool prime[MAX_N];
void make_prime()
{
    prime[2] = true;

    for (int i = 3; i < MAX_N; i += 2)
        prime[i] = true;

    for (int i = 3; i < MAX_N; i += 2)
        if (prime[i])
            for (int j = i + i; j < MAX_N; j += i)
                prime[j] = false;
}

int main()
{
    make_prime();

    for (;;) {
        int n;
        scanf("%d", &n);
        if (n == 0)
            break;

        int ans = 0;
        if (prime[n - 2])
            ++ans;
        for (int i = 3; i <= n / 2; i += 2)
            if (prime[i] && prime[n - i])
                ++ans;

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

    return 0;
}

Measured memory_bytes: 1060
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String[] S = new String[N];

		for(int i = 0 ; i < N ; i++){
			S[i] = sc.next();
		}

		sc.close();



		int tmp = N;
		long M = 0;
		long A = 0;
		long R = 0;
		long C = 0;
		long H = 0;

		for(int i = 0 ; i < N ; i++){
			if(!S[i].substring(0, 1).equals("M") && !S[i].substring(0, 1).equals("A") && !S[i].substring(0, 1).equals("R") && !S[i].substring(0, 1).equals("C") && !S[i].substring(0, 1).equals("H")){
				tmp--;
			}
			else if(S[i].substring(0, 1).equals("M")){
				M++;
			}
			else if(S[i].substring(0, 1).equals("A")){
				A++;
			}
			else if(S[i].substring(0, 1).equals("R")){
				R++;
			}
			else if(S[i].substring(0, 1).equals("C")){
				C++;
			}
			else if(S[i].substring(0, 1).equals("H")){
				H++;
			}
		}

		if(tmp == 0){
			System.out.println("0");
		}
		else{
			long[] T = {M,A,R,C,H};

			long ans = 0;
			for(int i = 0 ; i < 5 ; i++){
				for(int j = i+1 ; j < 5 ; j++){
					for(int k = j+1 ; k < 5 ; k++){
						ans += (T[i]*T[j]*T[k]);
					}
				}
			}

			System.out.println(ans);
		}

	}
}

Measured memory_bytes: 64144
N=int(input()) 
clist=[-1]
mod=10**9+7

for i in range(N):
  t=int(input())
  if t==clist[-1]:
    continue
  clist.append(t)

del clist[0]
N = len(clist)

# print(clist)
colorlast=[-1]*(3*10**5)
poslp=[-1]*(N+1)

for e,c in enumerate(clist,1):
  if  colorlast[c]  !=  -1:
    poslp[e]=colorlast[c]
    colorlast[c]=e
  else:
    colorlast[c]=e


dp=[0]*(N+100)
dp[0]=1

for e,c in enumerate(clist,1):
  if poslp[e]==-1:
    dp[e]=(dp[e-1])%mod
  else:
    dp[e]=(dp[e-1]+dp[poslp[e]])%mod

# print(dp[:len(clist)+1])
print(dp[len(clist)]%mod)
    



Measured memory_bytes: 27548
#include<iostream>
#include<cmath>
using namespace std;
const int N = 2e5+5;
int arr[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    for(int i =0;i<T;i++)
    {
        cin>>arr[i];
    }
    long long total=0;
    for(int i =0;i<T;i++)
    {
        int j;
        for(j = i+1;j<T;j++)
        {
            if(arr[j]<arr[i])
            {
                total+=arr[i]-arr[j];
            }
            else
            {
                i=j-1;
                break;
            }
        }
        if(j==T)
            break;
    }
    cout<<total;
    
}


Measured memory_bytes: 4364
class Problem
  attr_accessor :a, :b, :c, :n, :m, :h, :w
  def initialize
    @a,@b,@c = gets.to_s.split.map{ |v| v.to_i }
  end

  def solve
    a == b && b == c
  end

  def show(ans)
    puts ans ? "Yes" : "No"
  end
end

Problem.new.instance_eval do
  show(solve)
end

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  vector< vector<int> > dp(n + 1, vector<int>(3));
  for (int i = 0; i < n; i++) {
    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i];
    dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b[i];
    dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i];
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << '\n';
  return 0;
}

Measured memory_bytes: 6912
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

vvll to, ot;
vll ord;
vector<bool> seen;
void dfs(ll u) {
  seen[u] = true;
  for (ll v : to[u]) {
    if (seen[v]) continue;
    dfs(v);
  }
  ord.push_back(u);
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;
  to.resize(n), ot.resize(n);
  seen.resize(n);
  rep(i, n + m - 1) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    ot[b].push_back(a);
  }

  rep(i, n) {
    if (seen[i]) continue;
    dfs(i);
  }
  Reverse(ord);

  vll myord(n);
  rep(i, n) myord[ord[i]] = i;

  rep(i, n) {
    ll ans = 0;
    ll pos = -1;
    if (ot[i].size() == 0) {
      ans = -1;
      goto PUT;
    }
    for (ll u : ot[i]) {
      if (myord[u] > pos) {
        ans = u;
        pos = myord[u];
      }
    }
  PUT:
    cout << ans + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 16632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> cards(N);
  for (int i = 0; i < N; i++) {
    cin >> cards[i];
  }
  int alice, bob = 0;
  for (int i = 0; i < N; i++) {
    int max = *max_element(cards.begin(), cards.end());
    int max_index = max_element(cards.begin(), cards.end()) - cards.begin();
    cards.erase(cards.begin() + max_index);
    if (i % 2 == 0) alice += max;
    else bob += max;
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
import qualified Data.Map.Strict as M
import Data.Maybe

main = do
    n <- readLn :: IO Int
    let ab = M.fromListWith (+) $ map ((\s -> ((head s, last s),1)) . show) [1..n]
        ans = [(fromMaybe 0 (M.lookup (i, j) ab)) * (fromMaybe 0 (M.lookup (j, i) ab))| i <- ['1'..'9'], j <- ['1'..'9']]
    print $ sum ans

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans=0;
  REP(i,101){
    if(a<=i && i<=b && c<=i && i<=d){
      ans++;
    }
  }
  if(ans){
    ans--;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

using namespace std;
double dp[100010], sum;

signed main() {
    int n;
    cin >> n;
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        double p;
        cin >> p;
        for (int j = i; j >= 0; --j) {
            dp[j] = (j ? dp[j - 1] : 0) * p + dp[j] * (1 - p);
        }
    }
    for (int i = n; n - i < i; --i) sum += dp[i];
    printf("%0.10lf", sum);
}

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

int main()
{
    int c;
    cin>>c;
    
    while(c!=0){
        double sum=0;
        double bun=0;
        double a[c]={0};
        for(int i=0;i<c;i++){
           
            cin >>a[i];
            sum+=a[i];
            
        }
        for(int i=0;i<c;i++){
            bun+=pow(a[i]-sum/c,2)/c;
           
        }printf("%f",sqrt(bun));
        cout<<endl;
        cin>>c;
    }
}


Measured memory_bytes: 3240
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double xa, ya, ra, xb, yb, rb;
    double d;
    int num;

    cin >> num;
    for (int i = 0; i < num; i++) {
        cin >> xa >> ya >> ra >> xb >> yb >> rb;
        
        d = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));

        if (d > ra + rb) 
            cout << 0 << endl;
        else if (d < ra - rb)
            cout << 2 << endl;
        else if (d < rb - ra)
            cout << -2 << endl;
        else 
            cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1232