akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef long long lint;

char str[500005], rev[500005];
int n, fail[500005], rfail[500005];

bool ok1(int x){
	int v = x - fail[x];
	if(v == x || x % v != 0) return 1;
	return 0;
}

bool ok2(int x){
	int v = x - rfail[x];
	if(v == x || x % v != 0) return 1;
	return 0;
}

int main(){
	cin >> str;
	n = strlen(str);
	for(int i=0; i<n; i++){
		rev[n-1-i] = str[i];
	}
	int p = 0;
	for(int i=1; str[i]; i++){
		while(p && str[p] != str[i]){
			p = fail[p];
		}
		if(str[p] == str[i]) p++;
		fail[i+1] = p;
	}
	p = 0;
	for(int i=1; rev[i]; i++){
		while(p && rev[p] != rev[i]){
			p = rfail[p];
		}
		if(rev[p] == rev[i]) p++;
		rfail[i+1] = p;
	}
	int t = n - fail[n];
	if(t == n || n % t != 0){
		puts("1\n1");
		return 0;
	}
	if(t == 1){
		printf("%d\n1\n", n);
		return 0;
	}
	puts("2");
	int ret = 0;
	for(int i=1; i<n; i++){
		if(ok1(i) && ok2(n-i)) ret++;
	}
	printf("%d\n", ret);
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 1e5+5;
LL a[MAX];

int main()
{
        int n;
        cin >> n;
        LL sum = 0;
        for(int i = 1 ; i <= n ; i++)
        {
                cin >> a[i];
                sum += a[i];
        }
        LL dp[n+2][n+2];
        for(int gap = 0 ; gap <= n ; gap++)
        {
                for(int i = 1,j = gap ; j <= n ; i++,j++)
                {
                        LL x = (i+2 <= j)?dp[i+2][j]:0;
                        LL y = (i+1 <= j-1) ? dp[i+1][j-1]:0;
                        LL z = (i <= j-2) ? dp[i][j-2]:0;
                        dp[i][j] = max(a[i] + min(x,y) , a[j] + min(y,z));
                }
        }
        LL first = dp[1][n];
        LL second = sum - dp[1][n];
        cout << first - second << endl;
}


Measured memory_bytes: 70272
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
String A=scan.next();
String B=scan.next();
String C=scan.next();
int a=Integer.parseInt(A);
int b=Integer.parseInt(B);
int c=Integer.parseInt(C);
int okiba;
if(a>b){
okiba=a;
a=b;
b=okiba; 
}
if(b>c){
okiba=b;
b=c;
c=okiba; 
if(a>b){
okiba=a;
a=b;
b=okiba; 
}
}
System.out.println(a+" "+b+" "+c);
}
}

Measured memory_bytes: 26224
# include <stdio.h>
# include <stdbool.h>
# include <stdlib.h>

int main()

{
    int a,b ;
    scanf("%d %d",&a,&b);
    if (a<10&&b<10)
    {
        printf("%d",a*b);
    }
    else
    {
        printf("-1");
    }
    system("pause");
    return 0;

}

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

int main() {
    int h, w, result = -1;
    cin >> h >> w;
    string graph[h];
    for (int i = 0; i < h; i++) {
        cin >> graph[i];
    }
    queue<pair<int, int>> queue;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (graph[i][j] == '#') {
                queue.emplace(i, j);
            }
        }
    }
    do {
        for (auto size = queue.size(); size > 0; size--) {
            auto front = queue.front();
            queue.pop();
            int dir[] = {1, 0, -1, 0, 1};
            for (int i = 0; i < 4; i++) {
                int x = front.first + dir[i], y = front.second + dir[i + 1];
                if (x >= 0 && x < h && y >= 0 && y < w && graph[x][y] == '.') {
                    graph[x][y] = '#';
                    queue.emplace(x, y);
                }
            } 
        }
        result++;
    } while (!queue.empty());
    cout << result;
    return 0;
}

Measured memory_bytes: 9488
import           Control.Exception (assert)
import           Control.Monad     (replicateM)
import           Data.List         (foldl')
import           Data.Vector       ((!))
import qualified Data.Vector       as V (fromList)

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  s <- getLine
  assert (length s == n) $ do
    spells <- replicateM q $ do
      [t, d] <- words <$> getLine
      pure $ toSpell t d
    print $ solve n s spells

data Spell = Spell Char Direction

data Direction = L | R

toSpell :: String -> String -> Spell
toSpell [c] "L" = Spell c L
toSpell [c] "R" = Spell c R
toSpell _   _   = error "irregular"

solve :: Int -> String -> [Spell] -> Int
solve n s spells =
  let
    l = bisect (\i -> destination s spells i == LeftEdge) 0 n
    r = bisect (\i -> destination s spells i /= RightEdge) 0 n
  in
    r - l

bisect :: (Int -> Bool) -> Int -> Int -> Int
bisect p lowerB upperB -- section: [lowerB, upperB)
  | upperB - lowerB == 1 = lowerB
  | p middle             = bisect p middle upperB
  | otherwise            = bisect p lowerB middle
  where
    middle = (lowerB + upperB) `div` 2

data WithEdge a = LeftEdge | Inner a | RightEdge
  deriving (Eq)

-- Zipper で書くと TLE
destination :: String -> [Spell] -> Int -> WithEdge Char
destination s spells startIndex = array ! foldl' update (startIndex + 1) spells
  where
    array = V.fromList $ [LeftEdge] ++ map Inner s ++ [RightEdge]

    update i (Spell c d) =
      case (array ! i == Inner c, d) of
        (False, _) -> i
        (True, L)  -> pred i
        (True, R)  -> succ i


Measured memory_bytes: 74108
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, t;
	cin >> x >> t;
	x -= t;
	cout << max(0, x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int n, q,ans=0; long long a[100000] = {}, b[50000] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < q; i++) {
        int start = 0, goal=n;
        while (start<goal) {
            int mid = (start + goal) / 2;
            if (a[mid] == b[i]) {
                ans++;
                break;
            }
            else if (a[mid] > b[i]) goal = mid;
            else start = mid+1;
        }
    }
    cout << ans << endl;
}



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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,j,n) for(int i=j; i<n; i++)
#define INF 1000000000000000000 // If you use it, make sure not to put in "int" type variable ;(, use long long int
void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
const ll mod=1000000007;

int main()
{
    optimizeIO();
    int nT; nT=1;
	while(nT--)
	{
		int n; cin>>n;
		double a[n]; rep(i,0,n) cin>>a[i];
		sort(a,a+n);
		double now=(a[0]+a[1])/2.0;
		rep(i,2,n) now=(now+a[i])/2.0;
		cout<<now;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#define ull unsigned long long
using namespace std;
ull min(ull a,ull b)
{
	return a>b?b:a;
}
int main()
{
	ull q,h,s,d,n,ans=0;
	cin>>q>>h>>s>>d;
	cin>>n;
	ull mm=min(q*8,min(h*4,min(s*2,d)));
	ull m=min(q*4,min(h*2,s));
	ans=n/2*mm+m*(n&1);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
going1 = ''
returning1 = ''
going2 = ''
returning2 = '' 
a = tx - sx
b = ty - sy
going1 ='U' * b + 'R' * a
returning1 = 'D' * b + 'L' * a
going2 = 'L' + 'U' * (b + 1) + 'R' * (a + 1) + 'D'
returning2 = 'R' + 'D' * (b + 1) + 'L' * (a + 1) + 'U'
print(going1 + returning1 + going2 + returning2)



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

int main(){
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector <ll> p(a),q(b),r(c);
    rep(i,a){
        cin >> p[i];
    }
    rep(i,b){
        cin >> q[i];
    }
    rep(i,c){
        cin >> r[i];
    }
    
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    sort(r.rbegin(),r.rend());

    vector <ll> ans;
    

    rep(i,x){
        ans.push_back(p[i]);
    }
    rep(i,y){
        ans.push_back(q[i]);
    }

    

    ll kk=0,k=0;
    sort(ans.begin(),ans.end());
    while(r[k]>ans[kk]){
        ans[kk]=r[k];
        ++kk;
        ++k;
    }

    ll ans2=0;
    rep(i,x+y){
        ans2+=ans[i];
    }

    cout << ans2 << endl;





    

    

    

    return 0;
}

Measured memory_bytes: 7720
#文字列を入力
s = input()
sub_s = s[2:-1]

#先頭がA
res = s[0] == "A"
if res:
    #先頭から3文字目～最後から2文字目間にC
    res = sub_s.count("C") == 1
    if res:
        index = sub_s.index("C") + 2
        #A,C以外小文字
        res = s[1:index].islower() and s[index+1:].islower()

#出力
print("AC" if res else "WA")

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
    int a[10000],b[10000],ban[10000],i,n,ran,w;
	while(1){
	    scanf("%d",&n);
		if(n==0) break;
		ran=0;
		for(i=0;i<n;i++){
		    scanf("%d %d %d",&ban[i],&a[i],&b[i]);
		}
		for(i=0;i<n;i++){
		    if(ran<a[i]+b[i]){
			    ran=a[i]+b[i];
				w=i;
			}
		}
		printf("%d %d\n",ban[w],ran);
	}
	return 0;
}

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, C;
  cin >> N >> C;
  vec< int > x(N);
  vec< int > c(N);
  vec< vec< int > > sumC(2, vec< int >(N + 1));
  vec< vec< int > > cost(2, vec< int >(N + 1));
  cost[0][0] = cost[1][0] = 0;
  sumC[0][0] = sumC[1][0] = 0;
  REP(i, N) {
    cin >> x[i] >> c[i];
    sumC[0][i + 1] = sumC[0][i] + c[i];
  }
  REP(i, N) { sumC[1][i + 1] = sumC[1][i] + c[N - 1 - i]; }

  REP(i, N) {
    cost[0][i + 1] = max(cost[0][i], sumC[0][i + 1] - x[i]);
    cost[1][i + 1] = max(cost[1][i], sumC[1][i + 1] - (C - x[N - 1 - i]));
  }
  // PRINTALL(cost[0]);
  // PRINTALL(cost[1]);
  int ans = max(cost[0][N], cost[1][N]);
  // DEBUG(ans);
  REP(i, N) {
    //   DEBUG(sumC[0][i + 1] - 2 * x[i]);
    chmax(ans, cost[1][N - 1 - i] + sumC[0][i + 1] - 2 * x[i]);
  }
  REP(i, N) {
    chmax(ans, cost[0][N - 1 - i] + sumC[1][i + 1] - 2 * (C - x[N - 1 - i]));
  }
  print(ans);
}

Measured memory_bytes: 5744
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
char s[N];
int main(){ 
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    int ans = 0;
    s[0] = s[1];
    for (int i = 1; i <= len; i++) {
    if(s[i] != s[i - 1]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
p = list(map(int,input().split()))
for i in range(N): p[i] -= 1

par = [ i for i in range(N)]

def uf_root(a):
  if par[a] == a: return a
  par[a] = uf_root( par[a] )
  return par[a]

def uf_same(a,b):
  if (uf_root(a) ==uf_root(b)): return True

def uf_union(a,b):
  if (uf_same(a,b)): return
  a = uf_root(a)
  b = uf_root(b)
  par[a] = b
  return

for i in range(M):
  x,y = map(int, input().split())
  x -= 1
  y -= 1
  uf_union(x,y)

ans = 0
for i in range(N):
  if ( uf_same(i,p[i]) ):
    ans += 1
print(ans)



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

int get_digits(long n) {
  int cnt = 0;
  while (0 < n) {
    cnt += 1;
    n /= 10;
  }
  return cnt;
}

int main() {
  long N;
  cin >> N;

  int min = get_digits(N);
  for (long i = 1; i * i <= N; i++) {
    long A, B;
    if (N % i == 0) {
      A = i, B = N / i;
      int f = get_digits(max<long>(A, B));
      if (f < min) min = f;
    }
  }

  cout << min << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll dp[3001][6001];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, S;
	cin >> N >> S;
	int A[3000];
	rep(i, N) cin >> A[i];

	const int mod = 998244353;
	ll kotae = 0;
	rep(i, N) {
		if (S - A[i] > 0) kotae += dp[i][S - A[i]] * (N - i) % mod;
		if (S == A[i]) kotae += (i + 1) * (N - i);

		dp[i + 1][A[i]] += (dp[i + 1][A[i]] + i + 1) % mod;
		rep1(j, S - 1) {
			dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
			dp[i + 1][j + A[i]] = (dp[i + 1][j + A[i]] + dp[i][j]) % mod;
		}
	}


	co(kotae% mod);



	Would you please return 0;
}

Measured memory_bytes: 139776
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::set<int> s;
    for (int i = 0; i < 3; i++) {
        int in;
        std::cin >> in;
        s.insert(in);
    }

    std::cout << (s.size() == 2 ? "Yes" : "No") << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>

#define int64 long long int

using namespace std;

int main()
{
	int n;
	bool p[1000000] = {0};

	for(int i=2; i<=1000; i++){
		if(!p[i])
			for(int j=2*i; j<1000000; j+=i) p[j] = true;
	}

	while(cin >> n){
		int count = 0;
		for(int i=2; i<=n; i++)
			if(!p[i]) count++;
		cout << count << '\n';
	}

	return 0;
}

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

int main()
{
	//int h, w,   q, D, ax[90001], ay[90001], l[100000], r[100000];
	//long long int  i, j, k, l, a[100000], b[1000], c[1000], d[1000], e = 0, n, m, ten[1000] = { 0 }, ans = 0;
	int  i, j, k, l, a[100002], b[1000], c[1000], d[1000], e = 0, n, m, ten[1000] = { 0 }, ans = 0;
	//string st[1000], stm[1000];

	cin >> n;
	a[0] = 0;

	n++;
	a[n] = 0;
	for (i = 1; i <= n-1; i++)
	{
		cin >> a[i];
	}
	for (i = 1; i <= n; i++)
	{
		if (a[i] - a[i - 1] > 0)
		{
			ans += a[i] - a[i - 1];
		}
		else {
			ans -= a[i] - a[i - 1];
		}
	}
	for (i = 1; i <= n - 1; i++)
	{
		k = 0;
		if (a[i] - a[i - 1] > 0)
		{
			k -= a[i] - a[i - 1];
		}
		else {
			k += a[i] - a[i - 1];
		}
		if (a[i + 1] - a[i] > 0)
		{
			k -= a[i + 1] - a[i];
		}
		else {
			k += a[i + 1] - a[i];
		}
		if (a[i + 1] - a[i - 1] > 0)
		{
			k += a[i + 1] - a[i - 1];
		}
		else {
			k -= a[i + 1] - a[i - 1];
		}

		cout << ans + k << endl;

	}



	// 出力
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, m, i,ans[200005], an, x, y;
vector<int>adj[200005];

int dfs(int nod){
    int cur=0;
 for(auto x:adj[nod]){
    if(!ans[x]) dfs(x);
    cur=max(cur,ans[x]);
 }

 return ans[nod]=cur+1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);
   cin>>n>>m;
   for(i=1;i<=m;i++){
    cin>>x>>y;
    adj[x].pb(y);
   }
   /*for(i=1;i<=n;i++){
   for(auto x:adj[i]){
    dp[i]=max(dp[i],dp[x]+1);
   }}*/


   for(i=1;i<=n;i++){
        ans[i]=dfs(i);
        //cout<<dfs(i)<< " ";
    an=max(an ,ans[i]);
   }

   cout<<an-1;
    return 0;
}


Measured memory_bytes: 10496
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;

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



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

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

void treeDelete(Node *z){
  Node *y;  // 削除する対象
  Node *x;  // yの子
  // zは削除したいノード
  
  // 削除する節点を決める
  // zの子が一個以下のときzを削除。zに子がいない時はzを削除、子が1つでもそう 
  if (z->left == NIL || z->right == NIL)y = z;
  // zの子が二つの時は、zの次節点yのキーをzにコピー。yを消す
  else y = treeSuccessor(z);
  // yの子xを決める
  // yに左の子供がいる時
  if (y->left != NIL) {
    x = y->left;
  } else {
    // yに左の子供がいない時。右もいなかったら、NILになる。
    x = y->right;
  }
  // yに子供がいる時、yの親とxを繋ぐ
  if (x != NIL){
    x->parent = y->parent;
  }
  // yの親を決める
  if (y->parent == NIL ) {
    // 削除対象に親がいない時、削除したノードの子がrootになる
    root=x;
  } else {
    // 削除対象に親がいる時
    // 削除するノードが親の左の子のとき
    if (y == y->parent->left) {
      // 削除するノードの子を削除したノードの親の左の子供とする
      y->parent->left = x;
    } else {
      //　削除するノードが親の右の子のとき＼
      y->parent->right = x;
    }
  }
  // 削除したノードが、削除しようとしたノード出なかった時、つまり、削除しようとしたノードの左右に子供がいた時
  if (y != z) {
    // 削除したノードのキーをzのキーに
    z->key = y->key;
  }
  // 最後にyを削除
  free(y);
}

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

  z = (Node *)malloc(sizeof(Node));
  // pointerに対してのメモリの動的な割り当て。zポインタからNodeのポインタへ渡してるっぽい.二重割り当てか?
  // 確保したメモリをNode型ポインタへキャスト。構造体のsizeofは構造体メンバのバイト数
  z->key = k;  // zオブジェクトのポインタに対して参照
  // zはNode型へのポインタ型変数。あるノードへのアドレスが入る
  // 上でzが指すNode用のメモリが確保
  // ここではzつまり確保したノードのアドレスのkeyがさすアドレスに変数を代入
  z->left = NIL;
  z->right = NIL;
  // zに親の情報を入れ込む処理：yが親に相当
  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  // yに子の情報を入れる処理
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

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


int main() {
  int n, i, x;
  string com;
  scanf("%d", &n);

  for (i = 0; i< n; i++) {
    cin >> com;
    if (com[0] == 'f' ){
      scanf("%d", &x);
      Node *t = find(root, x);
      if (t != NIL)printf("yes\n");
      else printf("no\n");
    } else if (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com == "delete"){
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }
}


Measured memory_bytes: 22020
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N;
    cin >> N;
    vector<ll> A(N+2);
    ll total_dist = 0;
    A[0] = 0;
    for(size_t i=1;i<=N; i++)
    {
        cin >> A[i];
        total_dist += abs(A[i] - A[i-1]);
    }
    A[N+1] = 0;
    total_dist += abs(A[N+1] - A[N]);
    /*
    for(size_t i=0;i<A.size(); i++)
    {
        cerr << A[i] << endl;
    }
    cerr << total_dist << endl;
    */
    for(size_t i=1;i<=N; i++)
    {
        ll dist = total_dist;
        dist -= abs(A[i] - A[i-1]);
        dist -= abs(A[i+1] - A[i]);
        dist += abs(A[i+1] - A[i-1]);
        cout << dist << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 2176
s=input()
ans=0
c=1#連続数
temp=0
for i in range(len(s)):
    if i==0:
        ans+=1
    else:
        if s[i]==">" and s[i]==s[i-1]:
            c+=1
            if temp>=c:
                ans+=c-1
            else:
                ans+=c
        elif s[i]==">" and s[i]!=s[i-1]:
            temp=c
            c=1
        elif s[i]=="<" and s[i]==s[i-1]:
            c+=1
            ans+=c
        elif s[i]=="<" and s[i]!=s[i-1]:
            c=1
            tmp=0
            ans+=1
    #print(ans)
print(ans)

Measured memory_bytes: 4212
inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)


Measured memory_bytes: 192776
s = list(input())
n = len(s)

res = 0
for i in range(n):
    if i%2 == 0 and s[i] == '0':
        res += 1
    elif i%2 == 1 and s[i] == '1':
        res += 1

res2 = 0
for i in range(n):
    if i%2 == 0 and s[i] == '1':
        res2 += 1
    elif i%2 == 1 and s[i] == '0':
        res2 += 1
print(min(res,res2))

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

int main(){
    char c[10];
    scanf("%s",c);
    if (c[0]=='a' || c[0]=='i' || c[0]=='u' || c[0]=='e' || c[0]=='o') {
        printf("vowel\n");
    } else {
        printf("consonant\n");
    }
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {
  val input = readLine().split(" ").map(_.toInt)
  val a = input(0)
  val b = input(1)

  val sum = a + b
  val difference = a - b
  val product = a * b

  val list = List(sum, difference, product)
  val ans = list.max

  println(ans)
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);

  cout << fixed;

  int r, g, b, n;
  cin >> r >> g >> b >> n;

  ll ans = 0;

  REP(i, n / r + 1) {
    int nn = n;
    nn -= i * r;
    REP(j, nn / g + 1) {
      int nnn = nn;
      nnn -= j * g;
      if (nnn % b == 0) {
        // cout << i << " " << j << " " << nnn / b << endl;
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
	int n, m;
	char a[50][50], b[50][50];
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++){
		for (int j = 0; j < m; j++) {
			cin >> b[i][j];
		}
	}
	bool exist = false;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if ((i + m - 1 >= n) || (j + m - 1 >= n)) continue;
			bool match = true;
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (a[i + k][j + l] != b[k][l]) match = false;
				}
			}
			if (match) exist = true;
		}
	}
	if (exist) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;
typedef unsigned long long ull;

int N;
ull h[100002];

ull solve() {
  ull ans = 0;
  int last_j;
  stack<pair<int, ull>> s;
  pair<int, ull> tmp;
  for (int j = 1; j <= N+1; ++j) {
    if (s.empty() || (s.top().second < h[j])) {
      s.push(make_pair(j, h[j]));
    }
    else {
      while (!s.empty() && s.top().second >= h[j]) {
        last_j = s.top().first;
        ans = max(ans, (j-last_j)*(s.top().second));
        s.pop();
      }
      s.push(make_pair(last_j, h[j]));
    }
  }
  return ans;
}

int main () {
  cin>>N;
  for (int i = 0; i < N; ++i) {
    cin>>h[i+1];
  }
  cout<<solve()<<endl;
}


Measured memory_bytes: 5356
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<pair<vector<int>, int>> v(M);
  for (int i = 0; i < M; i++) {
    int k;
    scanf("%d", &k);
    v[i].first.resize(k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &v[i].first[j]);
    }
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &v[i].second);
  }
  int ans = 0;
  for (int i = 0; i < (1<<N); i++) {
    bool ok = true;
    for (int j = 0; j < M; j++) {
      int z = 0;
      for (auto it = v[j].first.begin(); it != v[j].first.end(); ++it) {
        z += (i&(1<<(*it-1))) ? 1 : 0;
      }
      if (z % 2 != v[j].second) {
        ok = false;
        break;
      }
    }
    if (ok)
      ans++;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int a[N];
int main()
{
    int n,flag=0;
    cin>>n;

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

        cout<<"Yes"<<endl;
        return 0;
    }
    int mmax=0;
    for(int i=1;i<n;i++){
        if(a[i]<a[i-1]){
            a[i]++;
        }
        if(a[i]<a[i-1]){
            flag=1;
            break;
        }
    }
    if(flag)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
#define N 360
#define int long long
int c[N][N],t[N],f[N],n,k,m;
void exp(int *a){
	memcpy(t,a,sizeof(t));
	for(int i=0;i<=n;i++)
		for(int j=0;j<i;j++)
			a[i]=(a[i]+t[j]*a[i-j-1]%m*c[i][j])%m;
}
signed main(){
	cin>>n>>k>>m;
	c[0][0]=1;
	for(int i=1;i<N;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++)
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%m;
	}
	n++;
	for(int i=0;i<n;i++)
		f[i]=1;
	k--;
	for(int i=1;i<=k;i++)
		exp(f);
	n--;
	cout<<f[n];
}

Measured memory_bytes: 1280
n,m=map(int,input().split())
xl=list(map(int,input().split()))
if n>=m:
    print(0)
    exit()
xl=sorted(xl)
dl=[]
for i in range(m-1):
    dl.append(abs(xl[i]-xl[i+1]))
dl=sorted(dl)
print(sum(dl[:m-n]))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

vector<pii> g[125252];
int ans[125252];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, a[125252], b[125252];
  cin>>n;
  REP(i, n-1){
    cin>>a[i]>>b[i];
    --a[i];--b[i];
    g[a[i]].emplace_back(b[i], i);
    g[b[i]].emplace_back(a[i], i);
  }
  int sz=1;
  queue<pii> q;
  q.emplace(0, 0);
  while(q.size()){
    auto ic=q.front();
    int i=ic.first, c=ic.second;
    q.pop();
    int col=1;
    for(auto& x : g[i]){
      int y=x.first, j=x.second;
      if(ans[j]){
        continue;
      }
      if(col==c){
        ++col;
      }
      ans[j]=col;
      q.emplace(y, col);
      CHMAX(sz, col);
      ++col;
      // DEBUG(y);
    }
  }
  cout<<sz<<'\n';
  REP(i, n-1){
    cout<<ans[i]<<'\n';
  }
  return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,ma=0,me=0;
  cin >> N;
  vector<ll> A(N);
  rep(i,N){
    cin >> A.at(i);
    ma=max(ma,A.at(i));
  }
  rep(i,N){
    if(ma%2==0){
      if(abs(ma/2-me)>abs(ma/2-A.at(i))){
        me=A.at(i);
      }
    }else{
      if(min(abs(ma/2-me),abs(ma/2+1-me))>min(abs(ma/2-A.at(i)),abs(ma/2+1-A.at(i)))){
        me=A.at(i);
      }
    }
  }
  cout << ma << " " << me << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll res = x % d;
	ll res2 = res - d;
	ll a = x / d;
	k -= a;
	if (k <= 0) {
		cout << x - d * (k + a) << endl;
	}
	else {
		if (k % 2 == 0) {
			cout << res << endl;
		}
		else {
			cout << abs(res2) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3604
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream& operator>>(istream& is, vector<T>& v);
template<class T> ostream& operator<<(ostream& os, vector<T> const& v);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream&, const tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream& os, const tuple<T...>& t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream& operator<<(ostream& os, const tuple<T...>& t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream&, tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream& is, tuple<T...>& t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream& operator>>(istream& is, tuple<T...>& t){ _it<0>(is, t); return is; }
template<class T> istream& operator>>(istream& is, vector<T>& v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

int const inf = 1<<28;
int H,W,S;
int a[33][33];

int T;
int sum[35][35];
pii dp[33][33][33][33];

inline int s(int x, int y, int w, int h){
    return sum[y+h][x+w]-sum[y][x+w]-sum[y+h][x]+sum[y][x];
}

// x,y,w,hの長方形でできる分割の数の最大、分割の最小
pair<int,int> f(int x, int y, int w, int h){
    auto & res = dp[x][y][w][h];
    if(res==mp(-1,-1)){
        if(s(x,y,w,h) < T) return res = mp(-inf,inf);
        else {
            res = mp(1,s(x,y,w,h));
            for(int i=1;i<w;i++){
                int a1,b1,a2,b2;
                tie(a1,b1)=f(x,y,i,h);
                tie(a2,b2)=f(x+i,y,w-i,h);
                res = max(res,mp(a1+a2,min(b1,b2)));
            }
            for(int i=1;i<h;i++){
                int a1,b1,a2,b2;
                tie(a1,b1)=f(x,y,w,i);
                tie(a2,b2)=f(x,y+i,w,h-i);
                res = max(res,mp(a1+a2,min(b1,b2)));
            }
        }
    }
    return res;
}

int main(){
    while(cin >> H >> W >> S && H){
        rep(i,33)rep(j,33)rep(k,33)rep(l,33)dp[i][j][k][l] = mp(-1,-1);
        rep(i,H)rep(j,W)cin >> a[i][j];
        memset(sum,0,sizeof(sum));
        rep(i,H)rep(j,W) sum[i+1][j+1] = a[i][j];
        rep(i,H+1)rep(j,W+1) sum[i][j+1] += sum[i][j];
        rep(i,H+1)rep(j,W+1) sum[i+1][j] += sum[i][j];
        T = sum[H][W]-S;
        int p,q;
        tie(p,q) = f(0,0,W,H);
        dump(p,q);
        cout << p << " " << q-T << endl;
    }
}

Measured memory_bytes: 10444
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

typedef ll Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void Dijkstra(const Graph &g, int s,
              vector<Weight> &dist, vector<int> &prev) {
    int n = (int)g.size();
    dist.assign(n, INF); dist[s] = 0;
    prev.assign(n, -1);
    priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
    for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
        Edge e = Q.top(); Q.pop();
        if (prev[e.dst] != -1) continue;
        prev[e.dst] = e.src;
        for(Edge f: g[e.dst]) {
            if (dist[f.dst] > e.weight+f.weight) {
                dist[f.dst] = e.weight+f.weight;
                Q.push(Edge(f.src, f.dst, e.weight+f.weight));
            }
        }
    }
}
int main() {
  int K;cin >> K;
  Graph g(K);
  repeat(i,K-1){
    g[i+1].push_back({(int)i+1,(int)(i+2)%K,1});
    g[i+1].push_back({(int)i+1,(int)(i+1)*10%K,0});
  }
  vector<Weight> dist;
  vint prev;
  Dijkstra(g,1,dist,prev);
  cout << dist[0]+1 << endl;
  return 0;
}


Measured memory_bytes: 9592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
using T  = tuple<int,int,int>;

int main(void){
    int k;cin>>k;
    cout<<10-k/200<<endl;
    
    return 0;
}

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

int main(){
    int x,y,temp;
    cin>>x>>y;
    while(1){
        if(y>x){
        temp=x;
        x=y;
        y=temp;
        }
        //cout<<x<<" "<<y<<endl;
        if(y%x==0){
            cout<<x<<endl;
            return 0;
        }
        x=x-y;

    }
    return 0;
}



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

p=1
if k<=n:
  for i in range(k):
    p=a[p-1]
  print(p)
  exit()

t=[-1]*n
t[0]=0
for i in range(1,n):
  p=a[p-1]
  if t[p-1] !=-1:
    break
  t[p-1]=i

d=i-t[p-1]
k-=i
k%=d
for i in range(k):
  p=a[p-1]
print(p)

Measured memory_bytes: 32412
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<vector<char>> vec(3,vector<char>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> vec.at(i).at(j);
        }
    }
    cout << vec.at(0).at(0) << vec.at(1).at(1) << vec.at(2).at(2) << endl;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    int a;
    string s;
    cin >> a >> s;

    cout << ((a >= 3200) ? s : "red") << endl;
}


Measured memory_bytes: 256
from operator import itemgetter

N = int(input())

AB = [tuple(map(int, input().split())) for i in range(N)]

AB = sorted(AB, key=itemgetter(1))

t = 0
ans = 'Yes'
for A, B in AB:
    if t + A > B:
        ans = 'No'
        break
    else: t += A
    
print(ans)

Measured memory_bytes: 33388
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        """[l, r)
        """
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret


@mt
def slv(N, P):
    pi = [(p, i) for i, p in enumerate(P)]
    pi.sort()
    p, i = pi.pop()
    lst = SegmentTree([-1]*N, max, -1)
    rst = SegmentTree([N]*N, min, N)
    lst.update(i, i)
    rst.update(i, i)

    ans = 0
    while pi:
        p, i = pi.pop()
        li = lst.query(0, i)
        lli = lst.query(0, li)
        ri = rst.query(i, N)
        rri = rst.query(ri+1, N)
        lst.update(i, i)
        rst.update(i, i)
        ln = (li-lli) * (ri-i)
        rn = (rri-ri) * (i-li)
        ans += ln * p
        ans += rn * p
    return ans


def main():
    N = read_int()
    P = read_int_n()
    print(slv(N, P))


if __name__ == '__main__':
    main()


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

#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";
std::string s;

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

// [解法1] ビット全探索
// void solve() {
//   std::string s;
//   std::cin >> s;
//   REP(i, (1 << 3)) {
//     std::bitset<3> b(i);
//     int sum = std::stoll(s.substr(0, 1));
//     std::string exp = s.substr(0, 1);
//     REP(j, 3) {
//       std::string d = s.substr(j+1, 1);
//       if (b.test(j)) {
//         sum += std::stoll(d);
//         exp += "+" + d;
//       } else {
//         sum -= std::stoll(d);
//         exp += "-" + d;
//       }
//     }
//     if (sum == 7) {
//       exp += "=7";
//       cout(exp);
//       return;
//     }
//   }
// }

// [解法2] 端から決めていく再帰で深さ優先探索
bool calc(int i, std::string exp, int sum);
void solve() {
  std::cin >> s;
  std::string exp = s.substr(0, 1);
  calc(0, exp, (int)s.at(0)-48);
}
bool calc(int i, std::string exp, int sum) {
  if (i == 3) {
    if (sum == 7) {
      cout(exp << "=7");
      return true;
    }
    return false;
  }
  if (calc(i+1, exp+"+"+s.at(i+1), sum+((int)s.at(i+1)-48))) {
    return true;
  }
  return calc(i+1, exp+"-"+s.at(i+1), sum-((int)s.at(i+1)-48));
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = -1;
        for(int i = 1;i <= 1000;i++){
            if(i*8/100==a && i/10==b){
                ans = i;
                break;
            }

        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23636
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) throws IOException
	{
	   BufferedReader br = new BufferedReader( new InputStreamReader ( System.in));
	   int n= Integer.parseInt(br.readLine());
	   int arr[]= new int[n];
	   
	   String line=br.readLine();
	   String strs[]=line.trim().split("\\s+");
	   
	   for(int i=0; i<n ;i++)
	   arr[i]=Integer.parseInt(strs[i]);
	   
	   int calc[][]=new int[n][2];
	   calc[0][0]=0;
	   calc[0][1]=0;
	   
	   if(n>1)
	   {
	       calc[1][0]=Math.abs( arr[1]-arr[0] );
	       calc[1][1]=Math.abs( arr[1]-arr[0] );
	   }
	   for(int i=2;i<n ; i++)
	   {
	       calc[i][0]=Math.min(calc[i-1][0] , calc[i-1][1]) + Math.abs(arr[i]- arr[i-1]) ;
	       calc[i][1]=Math.min(calc[i-2][0] , calc[i-2][1]) + Math.abs(arr[i]- arr[i-2]) ;
	   }
	   System.out.println( Math.min( calc[n-1][0] , calc[n-1][1]));
		//code
	}
}

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

int main()
{

        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

        int t=1;
        /// cin>>t;

        while(t--)
        {
            string a;
            cin>>a;
            int b=a.size();
            for(int i=0;i<b;i++) cout<<"x";
        }


         return 0;

    }


Measured memory_bytes: 256
import java.util.*;

public class Main {
	private static Scanner scan;
	public static void main(String[] args) {
		scan=new Scanner(System.in);
		while(scan.hasNext()){
			String ans="";
			int n=scan.nextInt();
			
			for(int i=10;i>=0;--i){
				int p=(int)Math.pow(2,i);
				if(n-p>=0){
					n-=p;
					ans=p+" "+ans;
				}
			}
			ans=ans.substring(0,ans.length()-1);
			System.out.println(ans);
		}
		scan.close();
	}
}

Measured memory_bytes: 17232
from itertools import product
n = int(input())
def factorization(num):
    result = []
    count = 0
    temp = num
    for i in range(2, int(num ** 0.5) + 1):
        if temp % i == 0:
            count = 0
            while temp % i == 0:
                count += 1
                temp /= i
            result.append([i, count])
    if temp != 1:
        result.append([temp, 1])
    if result == []:
        result.append([num, 1])
    return result
factors = factorization(n)
exps = [range(factor[1] + 1) for factor in factors]
ans = 1001001001001
for exp0 in product(*exps):
    f0 = 1
    for i in range(len(exp0)):
        f0 *= factors[i][0] ** exp0[i]
    f1 = n // f0
    ans = min(ans, f0 + f1 - 2)
print(int(ans))

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


int main() {
  ll p = 1000000007;
  ll p2 = p*2;

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
  }

  ll sum = 0;
  ll sum_s = 0;
  rep(i,n){
    sum += a.at(i);
    sum %= p2;
    sum_s += (ll)a.at(i)*(ll)a.at(i);
    sum_s %= p2;
  }


  int sqr = (sum*sum)%p2;
  int ans2 = sqr - sum_s;
  while(ans2<0)  ans2+=p2;
  int ans = ans2/2;
  cout << ans;
}

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

int main () {
  int a,b,c; cin>>a>>b>>c;
  if(a+b == c||b+c ==a || c+a == b){
    cout << "Yes";
    }else {
    cout << "No";
    }
  cout <<endl;
  
  return 0;
  }


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

public class Main{
	public static int combination(int n){
		return ( n < 10 ) ? n+1 : 19-n;
	}
	
	public static int solve(int x){
		int ans = 0;
		int i = 0;
		for(; i <= 18 && x-i >= 0; i++){
			if( x-i <= 18 ){
				ans += combination(x-i)*combination(i);
			}
		}
		return ans;
	}
		
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		int[] result = new int[100];
		int index = 0;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			int n = 0;
			while( stdIn.hasNext() ){
				if( stdIn.hasNextInt() ){
					n = stdIn.nextInt();
				} else {
					stdIn.next();
				}
				result[index] = solve(n);
				index++;			
			}
			for(int i = 0; i < index; i++){
				System.out.println(result[i]);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000