akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B; cin >> A >> B;
    REP(i,100){
        if((A-1)*(i-1)+A >= B){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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


int main(){
  int n = 0;
  while(1){
    cin >> n;
    if(n == 0) break;
    vector<int> score(n);
    for(int i = 0; i < n; i++){
      cin >> score[i];
    }

    sort(score.begin(), score.end());
    int sum = 0;
    for(int i = 1; i < n - 1; i++){
      sum += score[i];
    }
    cout << sum / (n - 2) << endl;
  }
  return 0;
}

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

int main() {
  string S, N;
  cin >> S >> N;

  bool answer = true;
  rep(i, S.length()) {
    if (S.at(i) != N.at(i)) {
      answer = false;
      break;
    }
  }

  if (answer) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  int n,k,i,h,count=0;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&h);
    if(h>=k)
      count++;
  }
  printf("%d\n",count);
  return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
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 RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 1e9+7;
const int MAXN = 2e5+3;
const int INF = 1e9;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    //int ntest; cin >> ntest; while(ntest--)
    {
        vector<LL> pw;
        for(int i = 0; ; i++) {
            LL p = 1LL*i*i*i*i*i;
            if(p > (LL)1e18) break;
            pw.pb(p);
        }
        //debugv(pw);
        //debug(pw.size());

        LL x; cin >> x;
        fori(i,pw.size()) {
            int found = 0;
            int ii,jj;
            fori(j,pw.size()) {
                if(pw[i]-pw[j] == x) {
                    ii = i; jj = j;
                    found = 1;
                } else if(pw[i]+pw[j] == x) {
                    ii = i; jj = -j;
                    found = 1;
                } else if(-pw[i]-pw[j] == x) {
                    ii = -i; jj = j;
                    found = 1;
                } else if(-pw[i]+pw[j] == x) {
                    ii = -i; jj = -j;
                    found = 1;
                }
                if(found) break;
            }
            if(found) {
                cout << ii << ' ' << jj << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ld,ld> pa;
const int N=5000+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,k;
ll fac[N],ifac[N],f[N][N][2];
ll C(ll n,ll m){
	if(n<0||m<0||n<m)return 0;
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
ll cata(int x){
	if(!x)return 1;
	if(x==1)return 1;
	return C(x+x,x)-C(x+x,x-1);
}
void add(ll&a,ll b){a+=b;a%=mod;}
int main(){
	read(n,k);
	/*fac[0]=1;
	rep(i,1,n)fac[i]=fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2,mod);
	repd(i,n-1,0)ifac[i]=ifac[i+1]*(i+1)%mod;
	ll res=C(n-1,k-1);
	cout<<res*qpow(2,n-k-1,mod)%mod;*/
	f[n][0][0]=1;
	repd(i,n,1)repd(j,n,0){
		add(f[i-1][j][0],f[i][j][0]+f[i][j][1]);
		add(f[i-1][j+1][1],f[i][j][0]+f[i][j][1]);
		if(j)add(f[i][j-1][0],f[i][j][0]);
	}
	ll res=(f[1][n-k][0]+f[1][n-k][1])%mod;
	if(n-k-1>=0)res=res*qpow(2,n-k-1,mod)%mod;
	cout<<res<<endl;
}

Measured memory_bytes: 156928
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

const int mod=1e9+7;

int solve(){
    int n,m; cin>>n>>m;
    string s[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>s[i];
    }
    int dp[n][m]={};
    dp[0][0]=1;
    for (int i = 0; i < n; ++i)
    {
        for(int j=0; j<m; j++){
            if(s[i][j]=='#') continue;
            if(i==0&&j==0) continue;
            if(i>0)
                dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
            if(j>0)
                dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
        }
    }
    cout<<dp[n-1][m-1];
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 12460
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> nakayoshi(n);
    rep(i, n) nakayoshi[i] = a[i];
    int ans = 0;
    rep(i, n) {
        if (nakayoshi[a[i]] == i) ans++;
    }
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 1024
i = readlines[0].to_i
if i < 112
  p 111
elsif i < 222
  p 222
elsif i < 333
  p 333
elsif i < 445
  p 444
elsif i < 556
  p 555
elsif i < 667
  p 666
elsif i < 778
  p 777
elsif i < 889
  p 888
elsif i < 1000
  p 999
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll>pairs;
int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,l,c,f;
	long double k;
	cin>>n;
	i=1;c=1;f=2;
	while(i<=n)
	{
	    cin>>k;
	    if(k==0){
	    c=0;f=1;}
	    else if(f)
	    {
	       if((k>1e18)||(1e18/k<c))
	         f=0;
	         else
	         c*=k;
	    }
	    i++;
	}
	if(f==0)
	cout<<-1;
	else
	cout<<(ll)(c);
	return 0;
}


Measured memory_bytes: 3748
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            ReadLine();
            var ST = ReadLine().Split().ToArray();
            var ans = "";
            for(var i=0;i<ST[0].Length;i++)
            {
                ans += ST[0][i];
                ans += ST[1][i];
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 18512
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using ll = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
     
int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> H;
    for (int i = 0; i < N; i++ ) {
        ll a;
        cin >> a;
        H.push_back(a);
    }
    if( N < K ){
        cout << 0 << endl;
    } else {
        sort( H.begin(), H.end() );
        cout << accumulate( H.begin(), H.end() - K, 0LL ) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



int main() {
    int n, count=0;
    
    cin>>n;
    
    rep(i,n+1){
        string b = to_string(i);
        int degit = b.length();
        if(degit%2==1) count++;
    }
    count--;
    cout<<count<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  ll x;
  cin >> x;
  ll sum =100;
  ll ans = 0;
  while(sum<x){
    sum*=1.01;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
N, A, B, *HS = $stdin.read.split.map(&:to_i)
def cleared?(n)
  hs = HS.map{|h| h - B*n}.reject{|h| h <= 0}
  times = hs.map{|h| (h.to_f / (A-B)).ceil}.inject(0, :+)
  return times <= n
end
min = 0
max = HS.inject(0, :+) / B
p (min..max).bsearch{|n| cleared?(n)}


Measured memory_bytes: 40796
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) :par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool connect(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    ll a, b;
    for(int i=0;i<m;i++){

        cin >> a >> b;
        a--;b--;
        uf.connect(a,b);
    }
    int ans = 0;
    for(int i=1;i<n;i++){
        if(uf.root(0)!=uf.root(i)){
            uf.connect(0, i);
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

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

    if(n[0]==n[1] && n[1]==n[2] || n[1]==n[2]&&n[2]==n[3])    cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


    class Program
    {
        static void Main(string[] args)
        {
            string Input = Console.ReadLine();
            if(Input == "ABC"){
                Console.WriteLine("ARC");
            }else if(Input == "ARC"){
                Console.WriteLine("ABC");
            }
        }
    }


Measured memory_bytes: 17296
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 1000000007
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        if(p1.first!=p2.first)return p1.first<p2.first;
        else return p1.second<p2.second;
    }
}; 
ll n,m;
vvl graph;
const ll maxn=1e5+1;
ll dp[maxn];
ll rec(ll &s){
    if(dp[s]!=-1)return dp[s];
    ll ans=0;
    for(ll x:graph[s]){
        ans=max(ans,1+rec(x));
    }
    return dp[s]=ans;
}

int main()
{
    fio;
    cin>>n>>m;
    graph.resize(n);
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<m;i++){
        ll u,v;cin>>u>>v;
        u--;v--;
        graph[u].push_back(v);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans=max(ans,rec(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12984
import Control.Applicative
import Text.Printf

main :: IO()
main = do
    fullSec <- read <$> getLine :: IO Int
    let h = fullSec `div` 3600
        m = (fullSec `mod` 3600) `div` 60
        s = (fullSec `mod` 3600) `mod` 60
    printf "%d:%d:%d\n" h m s

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

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

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    char b;
    cin >> b;

    switch (b) {
        case 'A':
            cout << 'T' << endl;
            break;
        case 'T': 
            cout << 'A' << endl;
            break;
        case 'C':
            cout << 'G' << endl;
            break;
        case 'G':
            cout << 'C' << endl;
            break;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


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



int main() 
{
  ll N,M;
  cin >> N;
  vector<string> blue (N);
  rep (i,N)
  {
    cin >> blue.at(i);
  }
  cin >> M;
  vector<string> red (M);
  rep (i,M)
  {
    cin >> red.at(i);
  }
  ll a = 0,b = 0,c = 0;
  string str;
  rep(i,N)
  {
    a = 0;
    b = 0;
    rep(j,N)
    {
      str = blue.at(i);
      if (str == blue.at(j))
      {
        a++;
      }
    }
    rep (j,M)
    {
      if (str == red.at(j))
      {
        b++;
      }
    }
    c = max(c,a - b);
  }
  cout << c << endl;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   int n;cin>>n;
   if(n%111==0){
      rep(i,3)cout << n/111;
   }else{
      rep(i,3)cout << n/111+1;
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main(void){
	int i, n, j, k=0, flag=0;
	long long min = 0, z = 0;
	long long sum_sn = 0, sum_ar = 0;
	vector<int> a(200001);

	cin >> n;

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

	for (i = 1; i <= n; i++){
		sum_ar += a[i];
	}
	sum_sn += a[1];
	sum_ar -= a[1];
	min = abs(sum_sn - sum_ar);

	for (i = 2; i < n; i++){
		sum_sn += a[i];
		sum_ar -= a[i];
		z = abs(sum_sn - sum_ar);
		if (z < min) min = z;
	}
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 1024
from collections import deque

N, M = map(int, input().split())
EN, EM = [[] for i in range(N)], [[] for i in range(M)]
for i in range(N):
    IP = [int(k) for k in input().split()]
    EN[i] = [a-1 for a in IP[1:]]
    for j in IP[1:]:
        EM[j-1].append(i)

VN, VM = [False for i in range(N)], [False for i in range(M)]
Q = deque()
Q.append(0)
VN[0] = True
while Q:
    tempN = Q.popleft()
    VN[tempN] = True
    for m in EN[tempN]:
        if not VM[m]:
            VM[m] = True
            for n in EM[m]:
                if not VN[n]:
                    VN[n] = True
                    Q.append(n)

if False in VN: print("NO")
else: print("YES")

Measured memory_bytes: 31796
#include <stdio.h>

int main(void){
  int N;

  scanf("%d",&N);
  for(int i = 0;7*i <= N;i++){
    for(int j = 0;7*i+4*j <= N;j++){
      if(7*i+j*4 == N){
        printf("Yes\n");
        return 0;
      }
    }
  }

  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cout << x << endl;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD =998244353;
int MAX_A = 303030;

using mint = modint998244353;
vector<mint> d10, d11;

struct S
{
    mint val;
    mint size;
    S(mint v, mint s):val(v), size(s) {}
    S():S(0,0){}
};
using F = mint;
const F ID = 100;
S e() { return S(); } 
S op(S l, S r)
{
    return S(l.val*d10[r.size.val()]+r.val, l.size+r.size);
}
F id() { return ID; }
S mapping(F f, S x)
{
    if(f != id()) return S(f*d11[x.size.val()], x.size);
    return x;
}
F composition(F f, F g) { return (f == ID ? g : f); }
//lazy_segtree<S, op, e, F, mapping, composition, id>

int main()
{
    int N, Q;
    cin >> N >> Q;
    int M = N*4;
    d10 = vector<mint>(M);
    d10[0] = 1;
    rep(i,M-1) d10[i+1] = d10[i]*mint(10);
    d11 = vector<mint>(M);
    d11[0] = 0;
    rep(i,M-1) d11[i+1] = d11[i]*mint(10)+mint(1);

    vector<S> tmp(N, S(1,1));
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(tmp);
    rep(i,Q)
    {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        seg.apply(l, r, d);
        cout << seg.all_prod().val.val() << "\n";
    }
    return 0;
}


Measured memory_bytes: 16144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int INF=2000000000;
int main() {
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<int> dp(n,INF);
  dp[0]=0;
  for(int i=1; i<n; i++){
    for(int j=0; j<min(i,k); j++){
      dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]));
    }
  }
  cout << dp[n-1] << endl;
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int m = sc.nextInt();
		int d = sc.nextInt();

		int ans = 0;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= d; j++) {
				int d1 = j % 10;
				int d2 = j / 10;
				
				if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) {
					ans++;
				}
			}
		}
		
		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);


template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int A,B; cin >> A >> B;
	int ans = 0;
	if(A>B){
		ans += A;
		ans += max({A-1,B});
	}
	else{
		ans += B;
		ans += max({A,B-1});
	}
	cout << ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,j,m,p,k,q;
	char c,w;
  while(cin>>n,n){
  	int a[26]={0},i,f=1,q=0;
    for(i=1;i<=n;i++){
	  cin>>c;
	  for(a[c-'A']++,m=j=0;j<26;j++)if(max(m,a[j])==a[j]){k=j;m=a[j];}
	  for(p=j=0;j<26;j++)if(j!=k)p=max(p,a[j]);
	  if(m>n-i+p&&f){
	  	q=i;
	  	w=k+'A';
	  	f=0;
	  }
	}
	if(q>0)cout<<w<<' '<<q<<endl;
	else cout<<"TIE"<<endl;
  }
}

Measured memory_bytes: 3020
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int tmp1=0, tmp2=0;
    vector<int> a(n+1, 0), b(n, 0);
    for (int i = 0; i < n; i++)
    {
        if(s[i]=='#') tmp1++;
        a[i+1] = tmp1;
        
        int j = n-1-i;
        if(s[j]=='.') tmp2++;
        b[j]=tmp2;
    }
    int ans=n;
    for (int i = 0; i < n+1; i++)
    {  
        ans = min(a[i]+b[i], ans);
    }
    cout << ans << endl;
    

}


Measured memory_bytes: 2180
#include <stdio.h>
int main(){
  int count,i,cc;
  char data[33];
  while(1){
    for(i=0;i<32;i++){
      data[i]='0';
    }
    scanf("%s",data);
    if(data[0]=='#') break;
    if(data[0]=='q'||data[0]=='w'||data[0]=='e'||data[0]=='r'||data[0]=='t'||data[0]=='a'||data[0]=='s'||data[0]=='g'||data[0]=='z'||data[0]=='x'||data[0]=='c'||data[0]=='v'||data[0]=='b'||data[0]=='d'||data[0]=='f'){
      cc=1;
    }else if(data[0]=='y'||data[0]=='u'||data[0]=='i'||data[0]=='o'||data[0]=='p'||data[0]=='h'||data[0]=='j'||data[0]=='k'||data[0]=='l'||data[0]=='n'||data[0]=='m'){
      cc=2;
    }
    count=0;
    
    for(i=1;i<32;i++){
      if(data[i]=='q'||data[i]=='w'||data[i]=='e'||data[i]=='r'||data[i]=='t'||data[i]=='a'||data[i]=='s'||data[i]=='g'||data[i]=='z'||data[i]=='x'||data[i]=='c'||data[i]=='v'||data[i]=='d'||data[i]=='b'||data[i]=='f'){ 
    if(cc==2){
    count++;
    cc=1;  
    }
      }else if(data[i]=='y'||data[i]=='u'||data[i]=='i'||data[i]=='o'||data[i]=='p'||data[i]=='h'||data[i]=='j'||data[i]=='k'||data[i]=='l'||data[i]=='n'||data[i]=='m'){
    if(cc==1){
    count++;
    cc=2;
    }
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  vi v(n);
  for(int& x : v){
    cin >> x;
  }
  sort(all(v));
  reverse(all(v));
  int a = 0, b = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0) a += v[i];
    else b += v[i];
  }
  cout << a - b;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[200],b[200],c[200],n,j,i=0;
	while(1)
	{
		if((scanf("%d %d",&a[i],&b[i]))==EOF) break;
		c[i] = a[i] + b[i];
		i++;
	}
	for(j=0;j<i;j++)
	{
		for(n=1;1;n++)
		{
			if(c[j]/10 == 0)break;
			c[j]/=10;
		}
		printf("%d\n",n);
	}
	
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, n, a) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;

void solve(){
    int n;
    cin >> n;
    int a[N], b[N], c[N];
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    int cnt = 0;
    int dpa[N], dpb[N], dpc[N];
    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];
    Rep(i, 1, n)   
    {
        dpa[i] = max(dpb[i - 1], dpc[i - 1]) + a[i];
        dpb[i] = max(dpa[i - 1], dpc[i - 1]) + b[i];
        dpc[i] = max(dpa[i - 1], dpb[i - 1]) + c[i];
    }
    cout << max(dpa[n - 1], max(dpb[n - 1], dpc[n - 1]));
}

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


Measured memory_bytes: 2560
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        mut x: i64, mut y: i64,
    }
    let mut cnt = (x.abs() - y.abs()).abs();
    if x == 0 {
        if y < 0 {
            cnt += 1;
        }
    } else if y == 0 {
        if x > 0 {
            cnt += 1;
        }
    } else if x * y >= 0 {
        if x > y {
            cnt += 2;
        }
    } else {
        cnt += 1;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
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; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(20)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N, K;
    cin >> N >> K;
    long a[N];
    cins(a, a + N);
    long ans = 1e18;
    for(int i = 0; i < (1 << N); i++){
        if(bitcount(i) < K){
            continue;
        }
        long this_ans = 0, now_max = 0;
        for(int j = 0; j < N; j++){
            if((i >> j) & 1){
                this_ans += max(0l, now_max + 1 - a[j]);
                now_max = max(now_max + 1, a[j]);
            }else{
                now_max = max(now_max, a[j]);
            }
        }
        ans = min(ans, this_ans);
    }
    cout << ans << endl;
}


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

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

    int a;

    a=word.size();

    if(word.at(a-1)=='s'){
        cout << word << "es" << endl;
    }else{
        cout << word << "s" << endl;
    }
}

Measured memory_bytes: 3624
#include <stdio.h>

#define LIMIT 1000000007

int main(void){
  int i,n;
  long long int m,ans=1;
  scanf("%lld %d", &m, &n);
  for(i=0;(1<<i)<=n;i++){
    if((1<<i)&n){
      ans*=m;
      if(ans>=LIMIT){
	ans%=LIMIT;
      }
    }
    m*=m;
    if(m>=LIMIT){
      m%=LIMIT;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
bool mo[60];
int main(){
    int a, b, c; scanf("%d%d%d", &a, &b, &c);
    int now = 0;
    memset(mo, 0, sizeof(mo));
    while(true){
        int q = now % 60, cc = 60 * (now / 60) + c;
        if(now <= cc && cc <= now + a){
            printf("%d\n", cc);
            break;
        }
        if(mo[q]){
            puts("-1");
            return 0;
        }
        mo[q] = true;
        now += a + b;
    }
    return 0;
}

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

int main() {
  int A,B,H,M;
  cin >> A>>B>>H>>M;
  double C,D,S,K;
  C=(60*H + M)*0.5;
  D=M*6;
  S =(C-D)*3.14159265358979323846/180;
  double U = cos(S);  
  K = A*A+B*B-2*A*B*U;
  double T;
  T = sqrt(K);
  cout <<setprecision(25)<<T<<endl;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int p;
  int i;
};
bool operator<(const ST& x, const ST& y){
  if(x.i==y.i) return x.p < y.p;
  return x.i < y.i;
}

int main(){
  int N;
  cin >> N;
  vector<ST> v;
  rep(i,N){
    ST st;
    cin >> st.p;
    st.i = i;
    v.push_back(st);
  }
  sort(ALLOF(v),[](const ST& x, const ST& y){ return x.p > y.p; });

  ll ret = 0;
  set<ST> s;
  s.insert((ST){-2,-1});
  s.insert((ST){-1,-1});
  s.insert((ST){-2,N});
  s.insert((ST){-1,N});
  
  rep(i,N){
    ST st = v[i];
    s.insert(st);

    int rhs2 = N;
    int rhs1 = N;
    int pos = st.i;
    int lhs1 = -1;
    int lhs2 = -1;

    auto itr = s.find(st);
    itr++;
    rhs1 = itr->i;
    itr++;
    rhs2 = itr->i;
    
    auto itl = s.find(st);
    itl--;
    lhs1 = itl->i;
    itl--;
    lhs2 = itl->i;

    //cout << lhs2 << " " << lhs1 << " " << pos << " " << rhs1 << " " << rhs2 << endl;

    ll a = pos - lhs1;
    ll b = lhs1 - lhs2;
    ll c = rhs1 - pos;
    ll d = rhs2 - rhs1;

    //cout << a << " " << b << " " << c << " " << d << endl;
    ret += st.p * (b*c + a*d);
  }
  
  cout << ret << endl;
  
  return 0;
}



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

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	vector<int> ansvec;

	for(;;){
		int n, p;
		cin >> n >> p;
		if (n == 0) break;
		
		int bowlp = p;
		int turn = 0;
		int mayors[50]{0};
		for(;;){
			if (bowlp == 1 && mayors[turn] == p - 1) break;
			else if (bowlp == 0){
				bowlp += mayors[turn];
				mayors[turn] = 0;
			}
			else{
				mayors[turn]++;
				bowlp--;
			}

			if (turn == n - 1) turn = 0;
			else turn++;
		}
		ansvec.push_back(turn);
	}

	for (int ans : ansvec){
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<iostream>

using namespace std;

int main(void){
	int x[10000];
	
	for(int i=0;i<10000;i++){
		cin>>x[i];
		if(x[i]==0)break;
	}
	
	for(int i=0;i<10000;i++){
		if(x[i]==0)break;
		cout<<"Case "<<i+1<<": "<<x[i]<<endl;
		
	}
	return 0;
}
	
	


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ( a * b >= c * d){
        cout << a * b << endl;
    }
    else{
        cout << c * d << endl;
    }
    
}

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

using namespace std;

const int mod = 1000000007;

int mem[2010][2010];
int sum[2010][2010];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, k, i, j;
    scanf("%d%d", &n, &k);

    mem[1][1] = sum[1][1] = 1;
    for(i = 2; i <= n; i++)
    {
        for(j = 1; j <= i; j++)
        {
            mem[i][j] = (sum[i - 1][j - 1] + mem[i - 1][j]) % mod;
            sum[i][j] = (sum[i][j - 1] + mem[i][j]) % mod;
        }
    }

    int r = mem[n][k];
    for(i = 0; i < n - k - 1; i++)
        r = (2 * r % mod);

    printf("%d\n", r);
    return 0;
}


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

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

    string s, t;
    cin >> s >> t;

    int count = 0;

    if (s[0] == t[0])
        count++;
    if (s[1] == t[1])
        count++;
    if (s[2] == t[2])
        count++;

    cout << count;

    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
A = sorted(A)

if N % 2 == 1:
    mid = A[N // 2]
#     print(mid)
    A = sorted([abs(a-mid) for a in A])
#     print(A)
    print(sum(A[:2]) + 2 * sum(A[2:]))

else:
    mid1 = A[N // 2 - 1]
    mid2 = A[N // 2]
    A_ori = [a for a in A]
    
    # 1
    A = [abs(a-mid1) for a in A_ori]
    one = A.pop(N // 2)
    two = A.pop(N // 2 - 1)
    cand = one + two + 2 * sum(A)
    
    # 2
    A = [abs(a-mid2) for a in A_ori]
    one = A.pop(N // 2)
    two = A.pop(N // 2 - 1)
    cand2 = one + two + 2 * sum(A)

#     print(cand, cand2)
    print(max(cand, cand2))

Measured memory_bytes: 14900
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        String s = std.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            sb.append('x');
        }
        System.out.println(sb.toString());
    }
}


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

#define int long long

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

int N;
int a[50];
int cur[50];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int ans = 0;
    while (true) {
        int sum = 0;
        for (int i = 0; i < N; i++) {
            cur[i] = a[i] / N;
            sum += cur[i];
        }
        if (sum == 0) {
            break;
        }
        for (int i = 0; i < N; i++) {
            a[i] += sum - cur[i] - cur[i] * N;
        }
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long int lli;

int N = 1<<18; // > 200000
vector<lli> dp(N*2, 0);

lli best(int l, int r, int idx = 0, int ll = 0, int rr = -1) {
    if (rr < 0) rr = N;
    // cout << ll << " " << rr << endl;
    if (rr <= l || r <= ll) return 0LL;
    
    lli res;
    if (l <= ll && rr <= r) return dp[idx];
    else res = max(best(l, r, idx*2+1, ll, (ll+rr)/2), best(l, r, idx*2+2, (ll+rr)/2, rr));

    // if (ll == 0 && rr == N) cout << "return : " << l << " " << r << " " << res << endl;
    return res;
}

void update(int idx, lli val) {
    idx += N - 1;
    dp[idx] = val;
    while (idx > 0) {
        idx = (idx-1) / 2;
        dp[idx] = max(dp[idx*2+1], dp[idx*2+2]);
    }

    return;
}

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

    int n;
    vector<int> h(200000);
    vector<lli> a(200000);

    cin >> n;
    for (int i=0; i<n; i++) cin >> h[i];
    for (int i=0; i<n; i++) cin >> a[i];

    for (int i=0; i<n; i++) {
        h[i]--;
        update(h[i], a[i]+best(0, h[i]));
    }

    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 6656
N = int(input())
X = []
Y = []
H = []
for i in range(N):
  x, y, h = map(int, input().split())
  X.append(x)
  Y.append(y)
  H.append(h)
  if h > 0:
    x_, y_, h_ = x, y, h

for px in range(101):
  for py in range(101):
    H_ = h_ + abs(px-x_) + abs(py-y_)
    for i in range(N):
      if H[i] != max(H_ - abs(px-X[i]) - abs(py-Y[i]), 0):
        break
    else:
      print(px, py, H_)
      exit()


Measured memory_bytes: 3064
# ABC088C - Takahashi's Information
def main():
    arr = [list(map(int, input().rstrip().split())) for _ in range(3)]
    memo = []
    for i, j, k in arr:
        memo += [(i - j, j - k)]
    flg_1 = True if memo[0] == memo[1] == memo[2] else False

    memo = []
    for i in range(3):
        i, j, k = arr[0][i], arr[1][i], arr[2][i]
        memo += [(i - j, j - k)]
    flg_2 = True if memo[0] == memo[1] == memo[2] else False
    
    print("Yes" if flg_1 and flg_2 else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  int k,s;
  cin>>k>>s;
  int ans=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      int h=s-i-j;
        if(0<=h&&h<=k)ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256