akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }
  private static class Agent {
    int i;
    int j;
    Agent(int i, int j) {
      this.i = i;
      this.j = j;
    }
  }
  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int[][] cells;
    int h = sc.nextInt();
    int w = sc.nextInt();
    cells = new int[h][w];
    for (int i = 0; i < h; i++) {
      String row = sc.next();
      for (int j = 0; j < w; j++) {
        cells[i][j] = row.charAt(j) == '.' ? 1 : 0;
      }
    }
    int[][] mins = new int[h][w];
    for (int i = 0; i < h; i++) {
      Arrays.fill(mins[i], Integer.MAX_VALUE);
    }
    Deque<Agent> queue = new ArrayDeque<>();
    mins[0][0] = cells[0][0] == 1 ? 0 : 1;
    queue.add(new Agent(0, 0));
    while (!queue.isEmpty()) {
      Agent a = queue.poll();
      if (a.i + 1 < h) {
        int cost = mins[a.i][a.j];
        if (cells[a.i][a.j] == 1 && cells[a.i + 1][a.j] == 0) {
          cost += 1;
        }
        if (mins[a.i + 1][a.j] > cost) {
          mins[a.i + 1][a.j] = cost;
          queue.add(new Agent(a.i + 1, a.j));
        }
      }
      if (a.j + 1 < w) {
        int cost = mins[a.i][a.j];
        if (cells[a.i][a.j] == 1 && cells[a.i][a.j + 1] == 0) {
          cost += 1;
        }
        if (mins[a.i][a.j + 1] > cost) {
          mins[a.i][a.j + 1] = cost;
          queue.add(new Agent(a.i, a.j + 1));
        }
      }
    }
    System.out.println(mins[h - 1][w - 1]);
  }
}

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

int m, a, b, p[200], ans;

int main() {
	while (true) {
		cin >> m >> a >> b;
		if (m == 0)break;
		for (int i = 0; i < m; i++) {
			cin >> p[i];
		}
		sort(p, p + m);

		/*cout << "m:" << m << " a:" << a << " b:" << b << endl;
		for (int i = 0; i < m; i++) {
			cout << p[i] << " ";
		}
		cout << endl;*/

		int ans = 0, maxnum = 0;
		for (int i = a; i <= b; i++) {
			//cout << "i:" << i << " p[m-i]:" << p[m-i] << endl;
			if (maxnum <= p[m - i]-p[m - (i + 1)]) {
				maxnum = p[m - i] - p[m - (i + 1)];
				ans = i;
			}
		}

		cout << ans << endl;
	}
}


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

using namespace std;

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

    unordered_map<int, long long> counts;

    long long sum = 0;

    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        if (counts.find(k) == counts.end()) counts[k] = 0;
        counts[k]++;
        sum += k;
    }

    int q;
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        long long sub = counts[b] * b;
        long long add = counts[b] * c;
        sum -= sub;
        sum += add;
        counts[c] += counts[b];
        counts[b] = 0;
        cout << sum << endl;
    }

}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    bool ok = true, odd = false;
    rep(i, n) {
        cin >> a[i];
        if (a[i] >= 2) {
            ok = false;
        }
        if (a[i]%2) odd = true;
    }
    if (ok) {
        cout << "first" << endl;
        return 0;
    }
    if (odd) {
        cout << "first" << endl;
    }
    else {
        cout << "second" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
/*---- enazuma11-------  */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
#define F first
#define S second
#define M 1000000007
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll a,b,c;
	cin>>a>>b>>c;
	ll ans=0;
	if(a+b>=c)
	ans+=b+c;
	else 
	ans+=a+2*b+1;
	cout<<ans;
	return 0;
}

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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll ans =0;
	for1(i,n){ 
		ll temp =0;
		ll a =i;
		while(a >0 ){
			// cerr << "test" << endl;
			a /= 10;
			temp++;
		}
		if(temp %2 == 1){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
    int k,x;
    cin >> k >> x;
    for (int i = x-k+1; i < x+k -1; i++) {
        cout << i << " ";
    }
    cout << x+k-1 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        String str1 = s.substring(0, (n - 1) / 2);
        String str2 = s.substring(((n + 3) - 1) / 2);
        String answer = "No";
        if (checkKaibun(s) && checkKaibun(str1) && checkKaibun(str2)) {
            answer = "Yes";
        }
        System.out.println(answer);
        sc.close();
    }

    // 文字列sを反転
    private static String reverseStr(String s) {
        StringBuilder sb = new StringBuilder(s);
        sb.reverse();
        return sb.toString();
    }

    // 文字列sが回文かどうか判定
    private static boolean checkKaibun(String s) {
        if (s.equals(reverseStr(s))) {
            return true;
        }
        return false;
    }

}


Measured memory_bytes: 35244
A, B = map(int, input().split())
S = input()

res = True

if S[A] != '-':
  res = False

for i in range(A+B+1):
  if S[i] not in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] and i != A:
    res = False

if res:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    int a, b, m, amin = INT32_MAX, bmin = INT32_MAX, min_ans;
    cin >> a >> b >> m;
    int ara[a], arb[b];
    f(i, 0, a){
        cin >> ara[i];
        if(amin > ara[i]) amin = ara[i];
    }
    f(i, 0, b){
        cin >> arb[i];
        if(bmin > arb[i]) bmin = arb[i];
    }
    min_ans = amin + bmin;
    int x, y, c;
    f(i, 0, m){
        cin >> x >> y >> c;
        x--;
        y--;
        if(ara[x] + arb[y] - c < min_ans){
            min_ans = ara[x] + arb[y] - c;
        }
    }
    cout << min_ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int N,X,L[100];
    cin >> N >> X ;
    int i,j;
    for(i=0;i<N;i++){
        cin >> L[i];
        }
    int D[100];
    for(j=0;j<N;j++){
            D[0]=0;
            D[j+1]=D[j]+L[j];
            if(D[j+1]>X){
                break;
            }
    }
    cout << j+1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,x,ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x>=m)
		ans++;
	}
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	ll n;
	cin >> n;
	ll sqrt_n = sqrt(n + .1);
	vector<int> f(10050, 0);
	for (ll x = 1; x <= sqrt_n; x++)
	{
		for (ll y = 1; y <= sqrt_n; y++)
		{
			for (ll z = 1; z <= sqrt_n; z++)
			{
				ll tmp = x * x + y * y + z * z + x * y + y * z + z * x;
				if (tmp <= 10005)
				{
					f[tmp]++;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		cout << f[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3560
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll L;
    in >> L;
    long double ans = 0;


    ans = (long double) (L*L*L) / 27;
    out << setprecision(10) << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

vector<int> vecHCard;
vector<int> vecSCard;
vector<int> vecCCard;
vector<int> vecDCard;

void getCard( )
{
	for ( int i = 1; i <= 13; i++ )
	{
		vecHCard.push_back(i);
	}

	for ( int i = 1; i <= 13; i++)
	{
		vecSCard.push_back(i);
	}

	for ( int i = 1; i <= 13; i++)
	{
		vecCCard.push_back(i);
	}

	for ( int i = 1; i <= 13; i++)
	{
		vecDCard.push_back(i);
	}
}

void compareCard( char cardColor, int CardNum )
{
	if ( cardColor == 'H')
	{
		vector<int>::iterator itH = vecHCard.begin();
		for (; itH != vecHCard.end();)
		{
			if ( * itH == CardNum )
			{
				itH = vecHCard.erase(itH);
			}
			else
			{
				itH++;
			}
		} 
	}

	if ( cardColor == 'S')
	{
		vector<int>::iterator itS = vecSCard.begin();
		for (; itS != vecSCard.end();)
		{
			if ( * itS == CardNum )
			{
				itS = vecSCard.erase(itS);
			}
			else
			{
				itS++;
			}
		} 
	}

	if ( cardColor == 'C')
	{
		vector<int>::iterator itC = vecCCard.begin();
		for (; itC != vecCCard.end();)
		{
			if ( * itC == CardNum )
			{
				itC = vecCCard.erase(itC);
			}
			else
			{
				itC++;
			}
		} 
	}

	if ( cardColor == 'D')
	{
		vector<int>::iterator itD = vecDCard.begin();
		for (; itD != vecDCard.end();)
		{
			if ( * itD == CardNum )
			{
				itD = vecDCard.erase(itD);
			}
			else
			{
				itD++;
			}
		} 
	}
}
int main()
{
	int n;				
	char color;			
	int num;			
	cin>>n;
	getCard();
	for ( int i = 0; i < n; i++ )
	{
		cin>>color>>num;
		compareCard(color,num);
	}

	for ( int i = 0; i < vecSCard.size(); i++ )
	{
		cout << "S"<<" "<<vecSCard[i]<<"\n";
	}

	for ( int i = 0; i < vecHCard.size(); i++ )
	{
		cout<<"H"<<" "<<vecHCard[i]<<"\n";
	}

	for ( int i = 0; i < vecCCard.size(); i++ )
	{
		cout<<"C"<<" "<<vecCCard[i]<<"\n";
	}

	for ( int i = 0; i < vecDCard.size(); i++ )
	{
		cout<<"D"<<" "<<vecDCard[i]<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=100010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n,m;
int fa[Maxn],cnt[Maxn],a[Maxn];
LL sum[Maxn];
struct Edge{int x,y,d;}e[Maxn];
bool cmp(Edge a,Edge b){return a.d<b.d;}
int findfa(int x){return((fa[x]==x)?x:fa[x]=findfa(fa[x]));}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=m;i++)e[i].x=read(),e[i].y=read(),e[i].d=read();
	sort(e+1,e+1+m,cmp);
	for(int i=1;i<=n;i++)fa[i]=i,sum[i]=a[i],cnt[i]=0;
	int ans=0;
	for(int i=1;i<=m;i++)
	{
		int fx=findfa(e[i].x),fy=findfa(e[i].y);
		if(fx!=fy)
		{
			fa[fy]=fx;
			sum[fx]+=sum[fy];
			cnt[fx]+=cnt[fy]+1;
			if(sum[fx]>=e[i].d)ans+=cnt[fx],cnt[fx]=0;
		}
		else
		{
			cnt[fx]++;
			if(sum[fx]>=e[i].d)ans+=cnt[fx],cnt[fx]=0;
		}
	}
	printf("%d",m-ans);
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(void){
	int a,b,d,r ;
	double f ;
	scanf("%d %d",&a,&b) ;
	d=a/b ;
	r=a%b ;
	f=(double)a/(double)b ;
	printf("%d %d %lf\n",d,r,f) ;
	return 0 ;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

using tl = tuple<ll, ll, ll, ll>;

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

    ll x, y, z, k;
    cin>>x>>y>>z>>k;
    vl as(x), bs(y), cs(z);
    cin>>as>>bs>>cs;

    sort(rng(as));
    reverse(rng(as));
    sort(rng(bs));
    reverse(rng(bs));
    sort(rng(cs));
    reverse(rng(cs));

    priority_queue<tl> q;
    q.emplace(as[0] + bs[0] + cs[0], 0, 0, 0);
    ll cnt = 0;
    vector<vector<vector<bool>>> used(x, vector<vector<bool>>(y, vector<bool>(z)));
    while(!q.empty() && cnt < k) {
        tl t = q.top(); q.pop();
        ll s = get<0>(t);
        ll a = get<1>(t);
        ll b = get<2>(t);
        ll c = get<3>(t);
        if (used[a][b][c]) continue;
        used[a][b][c] = true;
        cout<<s<<endl;
        if (a + 1 < x) q.emplace(as[a + 1] + bs[b] + cs[c], a + 1, b, c);
        if (b + 1 < y) q.emplace(as[a] + bs[b + 1] + cs[c], a, b + 1, c);
        if (c + 1 < z) q.emplace(as[a] + bs[b] + cs[c + 1], a, b, c + 1);
        cnt++;
    }
}

Measured memory_bytes: 180480
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	char s[20+2], t[20+2];
	while(scanf("%20[a-z]\n%20[a-z]\n", s, t)==2)
	{
		int ls=strlen(s);
		int lt=strlen(t);
		bool ans=true;

		if(ls+1!=lt) ans=false;
		for(int i=0;i<ls;i++)
		{
			if(s[i]!=t[i]) ans=false;
		}
		printf("%s\n", ans?"Yes":"No");
	}
	return 0;
}


Measured memory_bytes: 1648
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second


int main() {
    int n;
    cin>>n;
    vector<pair<int,int>>xy(n);
    vector<int>a(n);
    for(int i=0;i<n;i++){
        a[i]=i;
    }
    for(int i=0;i<n;i++){
        cin>>xy[i].fi>>xy[i].se;
    }
    double ans=0;
    do{
        for(int i=0;i<n-1;i++){
            ans+=sqrt((xy[a[i+1]].fi-xy[a[i]].fi)*(xy[a[i+1]].fi-xy[a[i]].fi) + (xy[a[i+1]].se-xy[a[i]].se)*(xy[a[i+1]].se-xy[a[i]].se));
        }
    }
    while(next_permutation(a.begin(),a.end()));
    ll cnt=1;
    for(int i=1;i<=n;i++){
        cnt*=i;
    }
    cout<<setprecision(10)<<ans/cnt<<endl;




    return 0;
}


Measured memory_bytes: 256
using System;
class ProgramD
    {
        static void Main(string[] args)
        {
            //
            string input = Console.ReadLine();
            int n = int.Parse(input);
            string[] inputA = Console.ReadLine().Split(' ');
            int[] A = new int[n];
            int[] ans = new int[n];
            for(int i = 0; i < n; i++)
               A[i] = int.Parse(inputA[i]);
            
            int sum = 0;
            int sumA = 0;

            for(int i = 0; i < n; i++)
               sum += A[i];
            
            for(int i = 1; i < n; i = i + 2)
               sumA += A[i];
            
            ans[0] = sum - 2 * sumA;
            
            for(int i = 1; i < n; i++)
                ans[i] = 2 * A[i - 1] - ans[i - 1];
                
            for(int i = 0; i < n; i++)
            {
               Console.Write(ans[i]);
               Console.Write(" ");
            }
        }
    }

Measured memory_bytes: 29144
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
int main(){
    int w,h;
    while(cin>>h>>w,w+h){
    int sum=w*w+h*h; vector<pii>v;
    rep(i,151)rep(j,151){
        //i:h j:w
        if(i==0||j==0)continue;;
        if(((sum>i*i+j*j||j<=i)))continue;
        if(sum==i*i+j*j&&h<i)v.push_back(pii(sum,i));
        else if(sum<i*i+j*j)v.push_back(pii(i*i+j*j,i));
    }
    sort(all(v));
    //rep(i,10)cout<<v[i].first<<" "<<v[i].second<<endl;
    cout<<v[0].second<<" "<<sqrt((double)v[0].first-(v[0].second*v[0].second))<<endl;
    }
}

Measured memory_bytes: 3404
#include <stdio.h>
#include <algorithm>
using namespace std;

int n, num, arr[100000];
long long quitar=0;
/*struct valor{
    int numero = 0;
    int repeticion=0;
};
bool compare(valor a, valor b){
    return (a.numero < b.numero);
}

valor arr[100000], ;*/

int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &num);
        //arr[i].numero = num;
        arr[i] = num;
    }
    sort(arr, arr+n);
    int last = arr[0], cont=1;

    for(int i=1; i<n; i++){
        if(last == arr[i]){
            cont+=1;
        } else {
            if(cont >= last){
                quitar += (cont -last);
            } else {
                quitar += (cont);
            }
            last = arr[i];
            cont = 1;
        }
    }
    if(cont >= last){
        quitar += (cont -last);
    } else {
        quitar += (cont);
    }
    printf("%d\n", quitar);
}


Measured memory_bytes: 512
#include<stdio.h>
 
int main( void ) 
{
 
    int n;
    scanf( "%d", &n );
    
    int i, j;
    int num[10000]; 
    int cnt = n;
    for( i=0; i<n; i++ ) {
        scanf( "%d", &num[i] );
    }
    for( i=0; i<n; i++ ) {    
        if( 2 == *(num+i) ) { continue; }
        
        if( 0 != *(num+i)%2 ) {
            for( j=3; j*j<=*(num+i); j+=2 ) {
                if( 0 == *(num+i)%j ) {
                    cnt--;
                    break;
                }
            }
        } else {
            cnt--;
        }
        
    }
     
    printf( "%d\n", cnt );
    
    return 0;
}

Measured memory_bytes: 628
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    long long N;
    cin >> N;
    vector<long long> A(5);
    for (int i=0; i<5; i++) {
        cin >> A[i];
    }
    long long min=A[0];
    for (int i=1; i<5; i++) {
        if(A[i]<min){
            min=A[i];
        }
    }
    
    long long ans;
    
    if (N<min) {
        ans = 5;
    }
    else{
        ans=4+((N+min-1)/min);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

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

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 2e5 + 11;
const int INF = 2e9;
const ll INF64 = 3e18 + 1;
const double lil = 0.0000000000001;

//ifstream cin ("test.in");
//ofstream cout ("test.out");

int n, m, lazy[4*N], t[4*N];

vector<pi>v[N];

void update(int v, int tl, int tr, int l, int r, int val){

    if(lazy[v] && (tl != tr)){
        t[2*v] += lazy[v];
        lazy[2*v] += lazy[v];
        t[2*v + 1] += lazy[v];
        lazy[2*v + 1] += lazy[v];
        lazy[v] = 0;
    }

    if(l <= tl && tr <= r){

        t[v] += val;
        lazy[v] += val;
        return;
    }

    if(l > tr || r < tl)return;

    int mid = (tl + tr)/2;

    update(2*v, tl, mid, l, r, val);
    update(2*v + 1, mid + 1, tr, l, r, val);

    t[v] = min(t[2*v], t[2*v + 1]);
}

int mn(int v, int tl, int tr, int l, int r){

    if(lazy[v] && (tl != tr)){
        t[2*v] += lazy[v];
        lazy[2*v] += lazy[v];
        t[2*v + 1] += lazy[v];
        lazy[2*v + 1] += lazy[v];
        lazy[v] = 0;
    }

     if(l <= tl && tr <= r)return t[v];

     if(l > tr || r < tl)return INF;

     int mid = (tl + tr)/2;

     return min(mn(2*v, tl, mid, l, r),mn(2*v + 1, mid + 1, tr, l, r));
}



int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    cin >> n >> m;

    int sum = 0;

    for(int i = 1,l,r,val; i <= m; i++){
        cin >> l >> r >> val;
        v[r].pb({l,val});
        sum += val;
    }

    for(int i = 0; i <= 4*n; i++)t[i] = INF;

    update(1,0,n,0,0,-INF);

    int ans = 0;

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

        for(auto it : v[i - 1]){
            update(1, 0, n, 0, it.ff - 1, it.ss);
        }

        int best = mn(1,0,n,0,n);

        if(i == n + 1)ans = best;

        update(1, 0, n, i, i, best - INF);
    }

    rc(sum - ans);
}

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

int main()
{
    int N;
    std::vector<std::string> titles;
    std::vector<int> lengths;
    std::string X;

    std::cin >> N;

    titles.resize(N);
    lengths.resize(N);

    for (auto i = 0; i < N; i++)
    {
        titles[i].reserve(101);
        std::cin >> titles[i] >> lengths[i];
    }
    X.reserve(101);
    std::cin >> X;

    std::vector<int> indices;
    indices.resize(N);
    std::iota(indices.begin(), indices.end(), 0);

    for (auto char_idx = 0; indices.size() > 1; char_idx++)
    {
        indices.erase(
            std::remove_if(indices.begin(), indices.end(),
                           [&](int idx) {
                               return titles[idx][char_idx] != X[char_idx];
                           }),
            indices.end());
    }
    std::cout << std::accumulate(lengths.begin() + indices.front() + 1, lengths.end(), 0) << std::endl;

    return 0;
}

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

long long n, k;

ModInt<> solve();

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

  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res = 0;
  for (int i = k; i <= n + 1; ++i) {
    long long low = (long long)i * (i - 1) / 2, high = (2 * n - i + 1) * i / 2;
    res += high - low + 1;
  }
  return res;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    
    int ans = 0;
    for(int i = 1; i < n; i++){
        int cnt = 1,flag[26] = {};
        for(int j = 0; j < i; j++){
            for(int k = i; k < n; k++){
                if(s[j] == s[k]) flag[s[j]-'a']++;
            }
        }
        for(int l = 0; l < 26; l++){
            if(flag[l]) cnt++;
        }
        ans = max(ans,cnt);
    }

    cout << ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
N = len(s)
dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

ans = 100
for key in dic:
    temp = list(s)
    cnt = 0
    while temp.count(temp[0]) < len(temp):
        new = [0]*(len(temp)-1)
        for i in range(len(temp)-1):
            if temp[i] == key or temp[i+1] == key:
                new[i] = key
            else:
                new[i] = temp[i]
        cnt += 1
        temp = new
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 3192
#include <iostream>
#include <vector>

int main() {
  int N,M,C;
  std::cin >> N >> M >> C;
  using IntV = std::vector<int>;
  IntV B(M);
  for(auto &b:B)
    std::cin >> b;
  IntV A(N*M);
  for(auto &a:A)
    std::cin >> a;
  auto itr_a = A.begin();
  int cnt = 0;
  for(int i=0;i<N;i++){
    auto itr_b = B.begin();
    int sum=0;
    for(int j=0;j<M;j++)
      sum += *itr_a++ * *itr_b++;
    if(sum>-C)cnt++;
  }
  std::cout << cnt << std::endl;
  return 0;
}

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

int aniki[90001][2];
long long rip[90001];

int main(void) {
    int h, w, d, q;
    cin >> h >> w >> d;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;
            aniki[a][0] = i + 1;
            aniki[a][1] = j + 1;
        }
    }
    for (int i = 1; i <= d; i++) {
        int l = i, r = h * w, billy = 0;
        while (true) {
            rip[l] = billy;
            if (l + d > r) break;
            billy += abs(aniki[l + d][0] - aniki[l][0]) + abs(aniki[l + d][1] - aniki[l][1]);
            l += d;
        }
        
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << rip[r] - rip[l] << endl;
    }
}


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


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

int n , M[N][N];
int d[N];

int head , tail;
int Q[MAX];

void initialize(){
	
	head = tail = 0;
	
}

int isEmpty(){
	
	if( head == tail ){
		return 1;
	}else{
		return 0;
	}
	
}

int isFull(){
	
	if( head == ( tail + 1 ) % MAX ){
		return 1;
	}else{
		return 0;
	}
	
}

void enqueue( int x ){
	
	if( isFull() == 1 ){
		fprintf( stderr , "エラー(オーバーフロー)" );
	}else{
		Q[tail] = x;
		
		if ( tail + 1 == MAX ){
			tail = 0;
		}else{
			tail++;
		}
	}
	
}

int dequeue(){
	
	int x;
	
	if( isEmpty() == 1 ){
		fprintf( stderr , "エラー(アンダーフロー)" );
		exit(0);
	}else{
		x = Q[head];
		
		if( head + 1 == MAX ){
			head = 0;
		}else{
			head++;
		}
		
		return x;
	}
	
}

void bfs( int s ){
	
	enqueue(s);
	for( int i = 0; i < n; i++ ){
		d[i] = INFTY;
	}
	d[s] = 0;
	int u;
	
	while( !isEmpty() ){
		u = dequeue();
		for( int v = 0; v < n; v++ ){ 
			if( M[u][v] == 0 ){ continue; }
			if( d[v] != INFTY ){ continue; }
			d[v] = d[u] + 1;
			enqueue(v);
		}
	}
	for( int i = 0; i < n; i++ ){
		printf( "%d " , i+1 );
		if( d[i] == INFTY ){
			printf( "-1\n" );
		}else{ printf( "%d\n" , d[i] ); }
	}

}

int main( void ){
	
	int u , k , v;
	
	scanf( "%d" , &n );
	
	for( int i = 0; i < n; i++ ){
		for( int j = 0; j < n; j++ ){
			M[i][j] =0;
		}
	}
	
	for( int i = 0; i < n; i++ ){
		scanf( "%d" , &u );
		scanf( "%d" , &k );
		u--;
		for( int j = 0; j < k; j++){
			scanf( "%d" , &v );
			v--;
			M[u][v] = 1;
		}
	}
	
	bfs(0);
	
	return 0;
}



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

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for (int i=0; i<N; i++) cin >> H.at(i);
  int pt=0, mina=abs(1000*T-6*H.at(0) - 1000*A);
  for (int i=1; i<N; i++) {
    if (mina > abs(1000*T-6*H.at(i) - 1000*A)) {
      pt=i; mina = abs(1000*T-6*H.at(i) - 1000*A);
    }
  }
  cout << pt+1 << endl;
}

Measured memory_bytes: 256
import itertools

L,R=map(int, input().split())

for i in range((2*10**9)//2019+1):
	if L<=i*2019 and i*2019<=R:
		print(0)
		exit()

ans=2020

for h in range(L,R+1):
	for g in range(h+1,R+1):
		ans=min(ans,(h*g)%2019)

print(ans)

Measured memory_bytes: 9048
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}

long long gcd(long long a, long long b) {return b ? gcd(b, a % b) : a;}
long long lcm(long long m, long long n ){if((0 == m )||( 0 == n ))return 0;
    return ((m / gcd(m, n)) * n);
}
signed main(){
    cin >> W >> H;
    int c; cin >> c;
    cout <<W*H/gcd(W, H)/gcd(W, H)*c<< endl;
}





Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int r,g,b,n;
    cin>>r>>g>>b>>n;
    long long int result=0;
    REP(i,2+n/r){
        REP(j,2+n/g){
            if(n-(i*r)-(j*g)>=0&&(n-(i*r)-(j*g))%b==0){
                result++;
            }
        }
    }
    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 888
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String pat = "A{0,1}KIHA{0,1}BA{0,1}RA{0,1}";
        String s = sc.next();
        if(s.matches(pat)) System.out.println("YES");
        else System.out.println("NO");
        sc.close();
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    ll X, Y;
    cin >> X >> Y;
    rep(i,X+1){
        ll sum = i * 2 + (X - i) * 4;
        if(sum == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int count = 0;
		Scanner std = new Scanner(System.in);
		String a = std.next();
		String b = std.next();

		for(int i = 0; i < a.length(); i++){
			if(a.charAt(i) != b.charAt(i))
				count++;
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 41200
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s[3];
	cin >> s[0] >> s[1] >> s[2];

	if (s[0][s[0].size() - 1] == s[1][0] && s[1][s[1].size() - 1] == s[2][0])
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	cout << endl;
	
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  char a;
  cin >> a;
  char ans;
  switch(a){
    case 'A':
      ans = 'T';
      break;
    case 'T':
      ans = 'A';
      break;
    case 'G':
      ans = 'C';
      break;
    case 'C':
      ans = 'G';
      break;
    default:
      break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3492
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int P[N];
    int index[N+1];
    REP(i,N){
        cin >> P[i];
        index[P[i]] = i;
    }
    ll ans=0;
    multiset<int> S;
    REP(i,2){S.insert(-1); S.insert(N);}
    int left,right;
    bool exist_left,exist_right;
    int r1,r2,l1,l2;
    for(ll v=N;v>0;v--){
        int i = index[v];
        auto it = S.lower_bound(i);
        r1 = *it; r2 = *++it; it--;
        l1 = *--it; l2 = *--it;
        ll c = (ll)(l1-l2)*(r1-i) + (ll)(i-l1)*(r2-r1);
        ans += c * v;
        S.insert(i);
    }


    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;
int h,w;
int maze[50][50];

int main(void){
	cin>>h>>w;
	for(int i = 0 ; i < h ; i ++)for(int j = 0 ; j < w ; j ++){
		char c; cin>>c; maze[i][j] = c - '0';
	}
	for(int i = 1 ; i < w ; i ++)
		maze[0][i] = maze[0][i] + maze[0][i-1];
	for(int i = 1 ; i < h ; i++)
		maze[i][0] = maze[i][0] + maze[i-1][0];
	for(int i = 1 ; i < h ; i ++)for(int j = 1 ; j < w ; j ++){
		maze[i][j] = min(maze[i-1][j],maze[i][j-1]) + maze[i][j];
	}
	cout<<maze[--h][--w]<<endl;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  int n;
  cin>>n;
  int ans=n/3;
  cout(ans);
  return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double

using namespace std;

int n, a, b;

int main() {
	cin >> n >> a >> b;

	if(abs(a - b) & 1) {
		cout << "Borys\n";
	} else {
		cout << "Alice\n";
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static long exec(long f0, long y, int type, double r, long t) {
	long fond = f0;
	if(type == 0) {//tanri
	    long c = 0L;
	    for(int i = 0; i < y; ++i) {
		long B = (long)(fond*r);
		c += B;
		fond = fond - t;
	    }
	    fond += c;
	} else {
	    for(int i = 0; i < y; ++i) {
		long B = (long)(fond*r);
		fond = fond + B - t;
	    }
	}
	return fond;
    }

    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int m = s.nextInt();
	for(int tc = 0; tc < m; ++tc) {
	    long f0 = s.nextLong();
	    long y = s.nextLong();
	    int n = s.nextInt();
	    long ans = 0;
	    for(int i = 0; i < n; ++i) {
		long res = exec(f0,y,s.nextInt(),s.nextDouble(),s.nextInt());
		if(ans < res) ans = res;
	    }
	    System.out.println(ans);
	}
    }
}

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

int solve(int i, int m,int n,int a[]) {
	if (m == 0)return 1;
	if (i >= n)return 0;
	int res = solve(i + 1, m, n, a) || solve(i + 1, m - a[i], n, a);
	return res;
}

int main()
{
	int n;
	int a[20];
	int q;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int num;
		cin >> num;
		int ans = solve(0, num, n, a);
		if (ans == 1) cout << "yes\n";
		else cout << "no\n";
	}

	return 0;
}


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n;
int main(){
	scanf("%lld",&n);
	char s[10];
	ll ans=0;
	rep(i,1,n+1){
		sprintf(s,"%lld",i);
		if(strlen(s)%2==1)ans++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include<cstdio>
using ull = unsigned long long;

int main(){
	ull X, money = 100;
	scanf("%llu", &X);
	unsigned ans = 0;
	while(money < X){
		money += money/100;
		ans++;
	}
	printf("%u\n", ans);
	return 0;
}

Measured memory_bytes: 1728