akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

LL dp[2002][2002][2]; // xがi番目を選びyがj番目を選んだときの得点
// dp[i][j] = min()

void resolve() {
    int n,z,w;
    cin >> n >> z >> w;
    VLL a(n+2);
    REP(i,0,n) cin >> a[i+1];
    a[0] = z;
    a[n+1] = w;
    //dp[n-1][]
    dp[0][n][0] = abs(w - a[n]);
    REP(i,1,n) dp[i][n][0] = abs(a[i] - a[n]);
    REP(i,1,n) dp[i][n][1] = abs(a[i] - a[n]);
    for (int i = n-1; i >=1 ;--i) for (int j = i-1; j >=0; --j) {
        LL minabs = 2 * 1000000000;
        REP(k,i+1,n+1) minabs = min(minabs, dp[i][k][1]);
        dp[j][i][0] = minabs;
        LL maxabs = 0;
        REP(k,i+1,n+1) maxabs = max(maxabs, dp[i][k][0]);
    }
    LL ans = 0;
    REP(i,1,n+1) ans = max(ans, dp[0][i][0]);
    cout << ans << endl;

    /*
    dp[n-1][0] = abs(a[n-1] - w);
    dp[n-1][1] = abs(a[n-2] - a[n-1]);
    for (int i = n-2; i > 0; --i) {
        LL minabs = dp[n-1][1];
        REP(j, i + 1, n) minabs = min(minabs, dp[j][1]);
        dp[i][0] = minabs;
        LL maxabs = dp[n-1][0]; 
        REP(j, i + 1, n) maxabs = max(maxabs, dp[j][0]);
        dp[i][1] = maxabs;
    }
    */
}

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

Measured memory_bytes: 61824
#include <bits/stdc++.h>
using namespace std;
const int N=1000005;
int n,m;
int b[N],tb=0,a[N],ta;
int st[N],top=0;
char S[N],T[N];
int check(){
	for (int i=1;i<=m;i++)
		if (a[i]!=b[i])
			return 0;
	return 1;
}
int checksame(){
	for (int i=1;i<=n;i++)
		if (S[i]!=T[i])
			return 0;
	return 1;
}
int main(){
	scanf("%d%s%s",&n,S+1,T+1);
	T[0]='*';
	for (int i=1;i<=n;i++)
		if (T[i]!=T[i-1])
			b[++tb]=i;
	ta=tb;
	for (int i=n;i>=1;i--)
		if (i<=b[ta]&&S[i]==T[b[ta]])
			a[ta--]=i;
	m=tb;
	if (ta>0)
		return puts("-1"),0;
	if (checksame())
		return puts("0"),0;
	if (check())
		return puts("1"),0;
	st[top]=n+1;
	int ans=0,add=0;
	for (int i=m;i>=1;i--){
		int L=1,R=top,mid,now=top+1;
		while (L<=R){
			mid=(L+R)>>1;
			if (b[i]>=st[mid]-add)
				R=mid-1,now=mid;
			else
				L=mid+1;
		}
		ans=max(ans,top-now+1+1);
		add++;
		st[++top]=a[i]+add;
	}
	printf("%d",ans+1);
	return 0;
}


Measured memory_bytes: 13952
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100
 
static const int dx[4] = {0, -1, 0, 1}; 
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r','u','l','d'};
int MMGo[N2][N2];
 
struct puzzle { int f[N2], space, MD; };
 
puzzle state;
int limit; 
int path[LIMIT];
 
int getAllMD(puzzle pz) {
    int sum = 0;
    for ( int i = 0; i < N2; i++ ) {
        if ( pz.f[i] == N2 ) continue;
        sum += MMGo[i][pz.f[i] - 1]; }
    return sum;
}
 
bool isSolved() {
    for ( int i = 0; i < N2; i++ ) if ( state.f[i] != i + 1 ) return false;
    return true;
}
 
bool dfs(int depth, int prev) {
    if ( state.MD == 0 ) return true;
    if ( depth + state.MD > limit ) return false;
     
    int sx = state.space / N;
    int sy = state.space % N;
    puzzle tmp;
     
    for ( int r = 0; r < 4; r++ ) {
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
        if ( max(prev, r)-min(prev, r) == 2 ) continue;
        tmp = state;
         
        state.MD -= MMGo[tx * N + ty][state.f[tx * N + ty] - 1];
        state.MD += MMGo[sx * N + sy][state.f[tx * N + ty] - 1];
        swap(state.f[tx * N + ty], state.f[sx * N + sy]);
        state.space = tx * N + ty;
        if ( dfs(depth + 1, r) ) { path[depth] = r; return true; }
        state = tmp;
    }
    return false;
}
 
string iterative_deepening(puzzle in) {
    in.MD = getAllMD(in);
    for ( limit = in.MD; limit <= LIMIT; limit++ ) {
        state = in;
        if ( dfs(0, -100) ) {
            string ans = "";
            for ( int i = 0; i < limit; i++ ) ans += dir[path[i]];
            return ans;
        }
    }
     
    return "unsolvable";
     
}
int main() {
  int i,j;
    for (i = 0; i < N2; i++ )
        for (j = 0; j < N2; j++ )
            MMGo[i][j] = abs(i / N - j / N ) + abs(i % N - j % N);
    puzzle in;
     
    for (i = 0; i < N2; i++ ) {
        cin >> in.f[i];
        if ( in.f[i] == 0 ) {
            in.f[i] = N2;
            in.space = i;
             
        }
    }
    string ans = iterative_deepening(in);
    cout << ans.size() << endl;
    return 0;
     
}



Measured memory_bytes: 3196
# from collections import defaultdict
# import sys
# input = sys.stdin.readline


def main():
    num = int(input())
    data = list(map(int, input().split()))

    a = data[0]
    b = sum(data) - a
    ans = abs(a - b)
    for i in range(1, num - 1):
        a += data[i]
        b -= data[i]
        ans = min(ans, abs(a - b))

    print(ans)





if __name__ == '__main__':
    main()

Measured memory_bytes: 76752
#include<cstdio>

long long n,a,b;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	
	if(a>b) printf("0\n");
	else{
		if(n==1){
			if(a==b) printf("1\n");
			else printf("0\n");
		}
		else{
			printf("%lld\n",(b-a)*(n-2)+1);
		}
	}
	
	return 0;
}

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

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;

constexpr ll MAX_N = 100;
bool unused_edge[MAX_N][MAX_N];
ll cost[MAX_N][MAX_N];
vector<ll> G[MAX_N];
ll N, M;

struct token {
    ll cost;
    ll from;
    token() {
        cost = 1e18;
        from = -1;
    }
    token(ll cost, ll from) : cost(cost), from(from) {}
};

struct tokencomp {
    bool operator()(const token& l, const token& r) {
        return l.cost > r.cost;
    }
};

void dijkstra(ll from, ll to) {
    vector<token> least(N);
    
    priority_queue<token, vector<token>, tokencomp> que;
    que.push(least[from] = token(0, from));
    while (!que.empty()) {
        auto tok = que.top(); que.pop();
        for (auto g : G[tok.from]) {
            auto t = tok;
            // cout << t.pos << "->" << g << endl;
            ll newcost = t.cost + cost[t.from][g];
            if (newcost < least[g].cost) {
                t.cost = newcost;
                least[g] = t;
                
                t.from = g;
                if (g != to) {
                    que.push(t);
                }
            }
        }
    }
    
    // cout << "from " << from << " to " << to << ": ";
    // for (auto r : route) {
    //     cout << r << " -> ";
    // }
    // cout << "end" << endl;
    
    ll pos = to;
    while (true) {
        ll next = least[pos].from;
        if (pos == next) {
            break;
        }
        unused_edge[pos][next] = unused_edge[next][pos] = false;
        pos = next;
    }
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> M;
    
    for (ll i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        
        G[a].push_back(b);
        G[b].push_back(a);
        cost[a][b] = cost[b][a] = c;
        unused_edge[a][b] = unused_edge[b][a] = true;
    }
    
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            if (i != j) {
                dijkstra(i, j);
            }
        }
    }
    
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            // cout << i << "," << j << ": " << unused_edge[i][j] << endl;
            if (unused_edge[i][j]) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

struct BiconectedGraph{
  typedef pair<int,int> P;
  vector<vector<int> > G,C,T;
  vector<int> ord,low,belong;
  vector<P> B;
  int V;
  BiconectedGraph(){}
  BiconectedGraph(int n){
    G.clear();
    C.clear();
    T.clear();
    G.resize(n);
    C.resize(n);
    T.resize(n);
  }
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bool is_bridge(int u,int v){
    if(ord[u]>ord[v]) swap(u,v);
    return ord[u]<low[v];
  }
  void dfs(int u,int p,int &k){
    ord[u]=low[u]=k;
    ++k;
    for(int v:G[u]){
      if(v==p) continue;
      if(ord[v]>=0){
	low[u]=min(low[u],ord[v]);
      }else{
	dfs(v,u,k);
	low[u]=min(low[u],low[v]);
      }
      if(is_bridge(u,v)) B.push_back(P(u,v));
    }
  }
  void fill_component(int c,int u){
    C[c].push_back(u);
    belong[u]=c;
    for(int v:G[u]){
      if(belong[v]>=0||is_bridge(u,v)) continue;
      fill_component(c,v);
    }
  }
  void add_component(int u,int &k){
    if(belong[u]>=0) return;
    fill_component(k++,u);
  }
  
  void build(int n){
    int k=0;
    ord.clear();
    ord.resize(n,-1);
    low.clear();
    low.resize(n);
    belong.clear();
    belong.resize(n,-1);
    for(int u=0;u<n;u++){
      if(ord[u]>=0) continue;
      dfs(u,-1,k);
    }
    k=0;
    for(int i=0;i<(int)B.size();i++){
      add_component(B[i].first,k);
      add_component(B[i].second,k);
    }
    add_component(0,k);
    V=k;
    for(int i=0;i<(int)B.size();i++){
      int u=belong[B[i].first],v=belong[B[i].second];
      T[u].push_back(v);
      T[v].push_back(u);
    }
  }
};


signed main(){
  int n,m;
  cin>>n>>m;
  BiconectedGraph bg(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    bg.add_edge(a,b);
  }
  bg.build(n);
  cout<<bg.B.size()<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (true)
		{
			int n = sc.nextInt(),
				m = sc.nextInt();
			if (n == 0 && m == 0)
				break;
			
			int taro[] = new int[n];
			int taroTotal = 0;
			for (int i = 0; i < n; i++)
			{
				taro[i] = sc.nextInt();
				taroTotal += taro[i];
			}
			int hanako[] = new int[m];
			int hanakoTotal = 0;
			for (int i = 0; i < m; i++)
			{
				hanako[i] = sc.nextInt();
				hanakoTotal += hanako[i];
			}
			LOOP: {
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < m; j++)
					{
						if (taroTotal - taro[i] + hanako[j] == hanakoTotal - hanako[j] + taro[i])
						{
							System.out.printf("%d %d\n", taro[i], hanako[j]);
							break LOOP;
						}
					}
				}
				System.out.println(-1);
			}
		}
	}
}

Measured memory_bytes: 12000
I = [int(_) for _ in open(0).read().split()]
H, W = I[:2]
A = I[2:2 + H * W]
B = I[2 + H * W:]
D = [abs(a - b) for a, b in zip(A, B)]
dp = [0] + [1] + [0] * (W - 1)
for h in range(H):
    dpo = dp
    dp = [0] * (W + 1)
    for w, d in enumerate(D[W * h:W * (h + 1)]):
        s = dp[w] | dpo[w + 1]
        dp[w + 1] = (s << d) | (s >> d)
        if d:
            t = bin(s)[2:][::-1][:d + 1]
            t += '0' * (d + 1 - len(t))
            dp[w + 1] |= int(t, 2)
for i in range(160 * 80):
    if dp[-1] & 2**i:
        print(i)
        exit()


Measured memory_bytes: 78872
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int a,b;
   cin >> a >> b;

   int ans = 0;
   if(a>=13) ans = b;
   else if(a>=6) ans = b/2;
   else ans = 0;

   cout << ans << endl;





   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	unsigned long int a, b, c;
	

	scanf("%ld%ld", &a, &b);

	if ((a * 2 <= b) && (a * 4 >= b) && (b % 2 == 0)) {
		printf("Yes");

		return 0;
	}
	printf("No");

	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  for (int i=0; i<s.length(); i++) {
	if (s[i] == t[i]) continue;
    else {
      cout << "No";
      return 0;
    }
  } cout << "Yes";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<ll> C(N+1), D(N+1);
    C[0] = 0;
    D[0] = 0;
    for (int i = 1; i < N+1; i++) {
        D[i] = D[i-1] + A[i-1];
        if(A[i-1] >= 0){
            C[i] = C[i-1] + A[i-1];
        }
        else{
            C[i] = C[i-1];
        }
    }
    ll ans = 0;
    ll tmp;
    //i+1~i+K番目が白
    for (int i = 0; i < N-K+1; i++) {
        tmp = C[i] + C[N] - C[i+K];
        ans = max(ans, tmp);
    }
    //i+1~i+K番目が黒
    for (int i = 0; i < N-K+1; i++) {
        tmp = C[i] + C[N] - C[i+K] + D[i+K] - D[i];
        ans = max(ans, tmp);
    }
    printf("%lld\n", ans);
    



}

Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();

		int count=0;
		for(int i=1;i<=n;i++) {
			if(i<=k) {
				count+=x;
			}else {
				count+=y;
			}
		}
		System.out.println(count);
	}

	public static int res(int n) {
		if(n==1) {
			return 1;
		}

		return n+res(n-1);
	}
}




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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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

long long gcd(long long a, long long b)
{
	if (b == 0) return a;
	else return gcd(b, a%b);
}

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


int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll X, K, D; cin >> X >> K >> D;

	bool ismi = (X >= 0);
	X = abs(X);
	ll res;
	ll t = X / D;
	if (K <= t)
	{
		res = abs(X - D*K);
	}
	else
	{
		ll m;
		if (abs(X - D*t) < abs(X - D*(t+1)))
		{
			if (abs(K - t) & 1)
				res = abs(X - D*(t+1));
			else
				res = abs(X - D*t);
		}
		else
		{
			if (abs(K - (t+1)) & 1)
				res = abs(X - D*t);
			else
				res = abs(X - D*(t+1));
		}
	}

	std::cout << res << std::endl; 
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, otsuri;
  cin >> n;
  int tmp = n;
  
  while(1) {
    if(tmp <= 1000) {
      otsuri = 1000 - tmp;
      break;
    } else {
      tmp = tmp - 1000;
    }
  }
  cout << otsuri << endl;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cout<<"ACL";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x)
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   //#endif

    cin>>a;
    if(a==1){
        cout<<1<<endl;
        return 0;
    }
    while(a!=1){
        a=a/2;
    //    cout<<a<<endl;
        ++cn1;
    }
    //ut<<a<<endl;
   // cout<<cn1<<endl;
    ans=1;
    for(int i=1;i<cn1;i++){
        ans+=(1LL*1<<i);
        //cout<<" i = "<<i<<" ans= "<<ans<<endl;
    }

    ans+=(1LL*1<<cn1);
    cout<<ans<<endl;




    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}




Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors.*;
public class Main {
    public static void main(String[] args) {
        new Main().solve();
    }
    IO io = new IO();

    /// ********** 本体 ********** ///

    void solve() {
        String a = io.String();
        String b = io.String();
        int tmp = f(a,b);
        String ans = tmp==1?"GREATER":
                    tmp==0?"EQUAL":
                            "LESS";
        System.out.println(ans);
    }
    int f(String a,String b){
        if(a.length()!=b.length()){
            return a.length()>b.length()?1:-1;
        }
        for(int i=0;i<a.length();++i){
            int tmpA = Character.getNumericValue(a.charAt(i));
            int tmpB = Character.getNumericValue(b.charAt(i));
            if(tmpA!=tmpB){
                return tmpA>tmpB?1:-1;
            }
        }
        return 0;
    }


    void FOR(int a, int b, Consumer<Integer>act) { for(int i = a; i < b; ++i) act.accept(i); }
    void REP(int a, Consumer<Integer>act) { FOR(0, a, act); }
}
class IO{
    String[] nextBuff;
    int      buffCnt;
    Scanner  sc = new Scanner(System.in);
    public IO(){
        nextBuff = new String[0];
        buffCnt = 0;
    }
    String next() {
        if (buffCnt < nextBuff.length) return nextBuff[buffCnt++];
        String line = sc.nextLine();
        while (line == "") line = sc.nextLine();
        nextBuff = line.split(" ");
        buffCnt = 0;
        return nextBuff[buffCnt++];
    }
    public String String() { return next(); }
    public char   Char()   { return next().charAt(0);}
    public int    Int()    { return Integer.parseInt(next());}
    public long   Long()   { return Long.parseLong(next());}
    public double Double() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23764
import java.io.*
import java.util.*

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val inp = Main.InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = Main.TaskA()
    solver.solve(inp, out)
    out.close()
}

class Main {
    internal class TaskA {
        fun solve(inp: InputReader, out: PrintWriter) {
            val s1 = inp.next()
            val s2 = inp.next()
            var c1 = inp.nextInt()
            var c2 = inp.nextInt()
            val s = inp.next()
            if (s.compareTo(s1) == 0)
                c1--
            else
                c2--
            out.println("$c1 $c2")
        }
    }

    internal class InputReader(stream: InputStream) {
        private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)
        private var tokenizer: StringTokenizer? = null

        init {
            tokenizer = null
        }

        operator fun next(): String {
            while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
                try {
                    tokenizer = StringTokenizer(reader.readLine())
                } catch (e: IOException) {
                    throw RuntimeException(e)
                }
            }
            return tokenizer!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return next().toLong()
        }
    }
}


Measured memory_bytes: 29472
S = input()
XX, YY = int(S[:2]), int(S[2:])

msg = ["NA", "MMYY", "YYMM", "AMBIGUOUS"]

id = 0
if 0 < XX <= 12:
    id += 1
if 0 < YY <= 12:
    id += 2

print(msg[id])


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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, usize, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input! {
        c: [[i32; 3]; 3],
    }

    let c: Vec<_> = c.into_iter().map(|r| r.windows(2).map(|w| w[1] - w[0]).collect::<Vec<_>>()).collect();
    if (0..2).all(|j| c[0][j] == c[1][j] && c[1][j] == c[2][j]) { println!("Yes") }
    else { println!("No") }
}



Measured memory_bytes: 4352
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        int.Parse(Console.ReadLine());
        int[] S = Console.ReadLine().Split(' ')
                                         .Select(val => int.Parse(val))
                                         .ToArray();
        int.Parse(Console.ReadLine());
        int[] T = Console.ReadLine().Split(' ')
                                         .Select(val => int.Parse(val))
                                         .ToArray();
        int cnt = 0;
        foreach (int i in T)
        {
            if(S.Contains(i)) cnt++;
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 10364
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
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; }

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

    int x,k,ans=0;
	string s;
	cin >> k >> x;


	
	for(int i=x-k+1;i<=x+k-1;i++){
		cout << i << " ";
	}
}

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

int main(void){
    int n, m, x;
    cin >> n >> m >> x;
    
    int input;
    int left = 0, right = 0;
    int i;
    for(i = 1; i <= m; i++){
        cin >> input;
        if(input < x){
            left++;
        }else{
            right++;
        }
    }
    
    cout << ((left < right) ? left : right) << endl;
    
    return 0;
}


Measured memory_bytes: 384
N = int(input())
S = [int(i) for i in input().split(" ")]
L = [0]*N

for j in range(0,N):
  L[S[j]-1] = j+1
for k in range(N):
    if k==N-1:
        print("{}".format(L[k]),end="")
    else:
        print("{} ".format(L[k]),end="")
print("\n",end="")

Measured memory_bytes: 13812
#!/usr/bin/ruby
# coding: utf-8

PI = Math.acos(-1)
EPS = 0.00001

it = [4,1,4,1,2,1,2,1]

def dif(xs, ys)
  r = 0
  for i in 0...xs.length
    r += [xs[i], ys[i]].min
  end
  r
end

def less(xs, ys)
  for i in 0...xs.length
    if xs[i] < ys[i]
      return true
    elsif xs[i] > ys[i]
      return false
    end
  end
  return false
end

while true
  line = gets
  break if line == nil
  that = line.chomp.split.map{|x| x.to_i}

  mx = -1
  res = []
  for i in 0...10
    it.rotate!
    m = dif(it, that)
    if (m > mx) or ((m == mx) and (less it, res))
      mx = m
      res = it.clone
    end
  end
  puts res.join(' ')
end

Measured memory_bytes: 6144
'use strict';
const fs = require('fs');
const mod = BigInt(1e9+7);

function sum(...a) {
  var s = 0;
  for (var x of a) s += x;
  return s;
}


class ABC041 {
  static A(input) {
    var s, i
    input = input.trim().split('\n');
    [s, i] = input;
    i = parseInt(i, 10);
    console.log(s[i-1]);
  }
  static B(input) {
    var a, b, c;
    input = input.trim().split(' ').map(BigInt);
    [a, b, c] = input;
    var ans = a * b % mod * c % mod;
    ans = Number(ans);
    console.log(ans);
  }
  static C(input) {
    var [n, height] = input.trim().split('\n');
    height = height.split(' ').map(n => parseInt(n, 10));
    n = parseInt(n, 10);
    var height = Object.keys(height).map(key => [parseInt(key, 10)+1, height[key]]);
    height.sort((a, b) => b[1]-a[1]);
    for (var [i, _] of height) {console.log(i);}
  }
  static D(input) {
    var lines = input.trim().split('\n');
    var [n, m] = lines[0].split(' ').map(x => +x);
    var edges = new Array(n).fill(0);
    for (var i = 0; i < m; i++) {
      var [x, y] = lines[1+i].split(' ').map(x => +x);
      edges[x-1] |= 1<<(y-1);
    }
    var comb = new Array(1<<n).fill(null); comb[0] = 1;
    function count(edges, bit) {
      if (comb[bit] != null) {return comb[bit];}
      comb[bit] = 0;
      for (var i = 0; i < n; i++) {
        if (bit>>i&1 && !edges[i]) {
          var nxt_bit = bit & ~(1<<i);
          var nxt_edges = edges.slice();
          for (var j = 0; j < n; j++) {
            nxt_edges[j] &= ~(1<<i);
          }
          comb[bit] += count(nxt_edges, nxt_bit);
        }
      }
      return comb[bit];
    }
    console.log(count(edges, (1<<n)-1));
  }
}

class ABC173 {
  static A(input) {
    var n = +input.trim();
    console.log(Math.floor((n+999)/1000)*1000 - n);
  }
  static B(input) {
    var lines = input.trim().split('\n');
    var n = +lines[0];
    var cnt = {
      'AC': 0,
      'WA': 0,
      'TLE': 0,
      'RE': 0
    }
    for (var i = 0; i < n; i++) {
      cnt[lines[1+i]]++;
    }
    for (var [verd, c] of Object.entries(cnt)) {
      console.log(`${verd} x ${c}`);
    }
  }
  static C(input) {
    var lines = input.trim().split('\n');
    var [h, w, k] = lines[0].split(' ').map(x => +x);
    var c = lines.slice(1);
    var tot = 0;
    for (var i = 0; i < (1<<h); i++) {
      for (var j = 0; j < (1<<w); j++) {
        var cnt = 0;
        for (var y = 0; y < h; y++) {
          if (i>>y&1) continue;
          for (var x = 0; x < w; x++) {
            cnt += c[y][x]=='#' && !(j>>x&1);
          }
        }
        tot += cnt == k;
      }
    }
    console.log(tot);
  }
  static D(input) {
    var lines = input.trim().split('\n');
    var n = +lines[0];
    var a = lines[1].split(' ').map(x => +x);
    a.sort((a, b) => b-a);
    var m = Math.floor((n-2)/2);
    var s = a[0] + sum(...a.slice(1, 1+m))*2 + (n&1)*a[1+m];
    console.log(s);
  }
  static E(input) {
  }
  static F(input) {
  }
}


var input = fs.readFileSync('/dev/stdin', 'utf8');
ABC173.D(input);

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;




using Graph = vector<vector<int> >;
struct Diameter {
    vector<int> prev;

    pair<int, int> DiameterDFS(const Graph &G, int v, int p) {
        pair<int, int> res(v, 0);
        for (int i = 0; i < (int)G[v].size(); ++i) {
            if (G[v][i] == p) continue;
            pair<int, int> tmp = DiameterDFS(G, G[v][i], v);
            tmp.second++;
            if (tmp.second > res.second) res = tmp, prev[G[v][i]] = v;
        }
        return res;
    }

    vector<int> solve(const vector<vector<int> > &G) {
        prev.assign((int)G.size(), -1);
        pair<int, int> leaf = DiameterDFS(G, 0, -1);
        prev.assign((int)G.size(), -1);
        pair<int, int> t = DiameterDFS(G, leaf.first, -1);
        vector<int> res;
        int cur = t.first;
        while (cur != -1) res.push_back(cur), cur = prev[cur];
        return res;
    }
};

int N;
Graph G(200005, vi());

int main() {
    cin >> N;
    rep(i, N - 1) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    Diameter diam;
    vi res = diam.solve(G);
    int x = res.size();

    cout << (x % 3 == 2 ? "Second" : "First") << endl;

}

Measured memory_bytes: 21500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s1,s2;
    cin >> s1 >> s2;
    reverse(s2.begin(), s2.end());
    if(s1 == s2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3680
l=[]
for i in range(-100,201):
    l.append(i)
x,n=map(int,input().split())
p=list(map(int,input().split()))
flag=False
if p.count(x)==0:
    print(x)
    flag=True
for i in range(n):
    if p[i]!=x:
        l.remove(p[i])
a=l.index(x)
if not flag:
    if abs(x-l[a-1])<=abs(x-l[a+1]):
        print(l[a-1])
    else:
        print(l[a+1])


Measured memory_bytes: 9204
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] nanbon = new int[N];
        for (int i = 0; i < M; i++) {
            nanbon[sc.nextInt() - 1]++;
            nanbon[sc.nextInt() - 1]++;
        }
        for (int i = 0; i < N; i++) {
            System.out.println(nanbon[i]);
        }
    }
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    int curr = 1, count = 0;
    for(int i=0;i<n;i++)
    {
        if(v[i] == curr)
        {
            curr++;
        }
        else count++;
    }
    if(count == n) cout << "-1\n";
    else cout << count << "\n";

    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  string s;

  cin >> N;
  cin >> s;

  int ans = 1;
  REP(i, 0, N-1) {
    if (s[i] != s[i+1]){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int N, P;
  string S;
  cin >> N;
  vector<tuple<string, int, int>> V(N);
  for (int i = 0; cin >> S >> P; i++) V.at(i) = make_tuple(S, -P, i + 1);
  sort(V.begin(), V.end());
  for (auto v : V) cout << get<2>(v) << "\n";
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val a = sc.next()
  val b = sc.next()

  val ans = a(a, b)
  println(ans)
}

private fun a(a: String, b: String): String {
  val al = a.length
  val bl = b.length
  if (al < bl) return "LESS"
  if (bl < al) return "GREATER"

  for (i in 0 until al) {
    val ai = a[i]
    val bi = b[i]

    if (ai < bi) return "LESS"
    if (bi < ai) return "GREATER"
  }

  return "EQUAL"
}


Measured memory_bytes: 31272
def dfs(i):
    for j in '753':
        y[i]=j
        if i ==0:
            z = y.copy()
            x.append(z)
        else:
            dfs(i-1)

n = input()
ans = 0
y=['']*len(n)
x=[]
for i in range(2,len(n)):
    dfs(i)
for i in x:
    if int(''.join(i))<=int(n) and len(set(list(''.join(i))))==3:
        ans+=1
print(ans)


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

int main () {
int n;
cin >>n;
vector<int>d(n);
for (int i=0;i<n;i++){
  cin>>d[i];
}

int hp =0;
for (int i=0;i<n;i++){
  for (int j=0;j<i;j++){
    hp += d[i]*d[j];
  }
}
cout << hp <<endl;
}


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

int main() {
	
	string s;
	cin>>s;
	if(s=="Sunny") cout<<"Cloudy"<<endl;
	if(s=="Cloudy") cout<<"Rainy"<<endl;
	if(s=="Rainy") cout<<"Sunny"<<endl;
	
	
	
	return 0;
}

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

using namespace std;

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

    long long S;
    cin >> S;

    int l = 0, r = 1e9;
    while (l < r - 1) {
        int m = (l + r) / 2;
        if (1ll * m * m >= S) {
            r = m;
        } else {
            l = m;
        }
    }
    int a = r, d = r;
    long long bc = 1ll * a * d - S;
    assert(bc <= 1e9);
    int b = 1, c = bc;
    assert(1ll * a * d - bc == S);
    cout << 0 << ' ' << 0 << ' ' << a << ' ' << b << ' ' << c << ' ' << d << endl;
}

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

int main()
{
    int n;
    cin >> n;
    int A[n];
    int B[n+1];
    for(int i = 1; i <= n; i++){
        B[i] = 0;
    }
    for(int i = 1; i < n; i++){
        cin >> A[i];
        B[A[i]]++;
    }
    for(int i = 1; i <= n; i++){
        cout << B[i] << endl;
    }
}


Measured memory_bytes: 5184
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int ans = 0;
	for (int i = a; i <= b; i++) {
		auto s = to_string(i);
		auto t = s;
		reverse(t.begin(), t.end());
		if (s == t) {
			ans++;
		}

	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

long long a[100005], dp[100105], n, k;

int main(){
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        dp[i] = 1e9;
    }
    dp[1] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= k; j++)
            dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1792
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

# [Pl, Pr]間で２番目に大きいものの総和を
# l, rについてのnC2通りの全てについて求めよ

# 8 2 7 3 4 5 6 1
# 8 2: 2
# 8 2 7: 7
# 2 7 3: 3
# 8を含むもの（７通り）について2が２番目になるもの、7が２番目になるもの...
# 2を含むものについて（６通り）について7が...をそれぞれO(1)で求められれば

# N <= 10 ** 5
# Piが２番目になる通りが何通り　みたいな感じで求められる？
# Piが２番目になる条件　→　自分より上位のものを一つだけ含む

# ヒープキューとか使える？
# 二つ数字を入れる　→　最小値を取り出せばそれは２番目の数字
# 尺取り使える？

# 累積？　一番

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0] * (N + 1)
        self.b = 1 << N.bit_length() - 1

    def add(self, a, w):
        x = a
        while(x <= self.N):
            self.bit[x] += w
            x += x & -x

    def get(self, a):
        ret, x = 0, a - 1
        while(x > 0):
            ret += self.bit[x]
            x -= x & -x
        return ret

    def cum(self, l, r):
        return self.get(r) - self.get(l)

    def lowerbound(self,w):
        if w <= 0:
            return 0
        x = 0
        k = self.b
        while k > 0:
            if x + k <= self.N and self.bit[x + k] < w:
                w -= self.bit[x + k]
                x += k
            k //= 2
        return x + 1

N = getN()
P = getList()
dic = {}
bit = BIT(N)
for i in range(N):
    dic[P[i]] = i + 1

# 両端に何もない時用
# [0] + Pの各要素 + [N + 1]みたいになる
dic[0] = 0
dic[N + 1] = N + 1
ans = 0

for i in range(N, 0, -1):
    # 8のインデックス、7のインデックス...に1を登録していく
    bit.add(dic[i], 1)
    # 左側にある既に登録したもの（自分より大きいもの + 自分）の数を数える
    c = bit.get(dic[i] + 1)
    # l1: 左側にある既に登録したもの（自分より大きいもの）のうち、一番右にあるもの
    # l2: l1の一つ左側にあるもの
    l1, l2 = bit.lowerbound(c - 1), bit.lowerbound(c - 2)
    # r1: 右側にある既に登録したもの（自分より大きいもの）のうち、一番左にあるもの
    # r2: r1の一つ右側にあるもの
    r1, r2 = bit.lowerbound(c + 1), bit.lowerbound(c + 2)
    S = (l1 - l2) * (r1 - dic[i]) + (r2 - r1) * (dic[i] - l1)
    ans += S * i
print(ans)

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

int main() {
	int n, *h;
	cin>>n;
	h = new int[n];
	for(int i=0;i<n;++i){
		cin>>h[i];
	}
	for(int i=1;i<=n;++i){
		cout<<"node "<<i<<": key = "<<h[i-1]<<", ";
		if(i!=1)cout<<"parent key = "<<h[i/2-1]<<", ";
		if(i*2<=n)cout<<"left key = "<<h[i*2-1]<<", ";
		if(i*2+1<=n)cout<<"right key = "<<h[i*2]<<", ";
		cout<<endl;
	}
	return 0;
}

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

#き数回のあと 53124
#偶数回のあと 642135
ans = [0] * n

if n % 2 == 0:
  x = n // 2
  for i in range(n):
    if i % 2 == 1:
      ans[x - i//2 - 1] = a[i]
    else:
      ans[x + i//2] = a[i]
      
else:
  x = n // 2
  for i in range(n):
    if i % 2 == 1:
      ans[x + i//2 + 1] = a[i]
    else:
      ans[x - i//2] = a[i]
    
  
for i in range(n):
  print(ans[i], end = " ")

Measured memory_bytes: 26180
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    cout << (a+b)%24 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String n = sc.next();
      String[] ns = n.split("");
      if(ns[ns.length - 1].equals("2") || ns[ns.length - 1].equals("4") ||
        ns[ns.length - 1].equals("5") || ns[ns.length - 1].equals("7") || 
        ns[ns.length - 1].equals("9")){
		System.out.println("hon");
      } else if(ns[ns.length - 1].equals("3")){
      	System.out.println("bon");
      } else {
      	System.out.println("pon");
      }
      
      
	}
}

Measured memory_bytes: 35460
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a+b >= c) System.out.println("Yes"); 
		else System.out.println("No");
	}
}

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

int main(){
    int n, l, r;
    int sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> l >> r;
        sum += r-l+1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)


def shugyou_count(X):
    # 目標スコアをXとしたときの必要修行回数を求める
    count = 0
    for a, f in zip(A, F):
        count += max(0, a - X // f)
    return count


# 二分探索で達成可能な最小値を見つける
l = -1
r = max(A) * max(F)
while l + 1 < r:
    X = (l + r) // 2
    if shugyou_count(X) <= K:
        r = X
    else:
        l = X
print(r)



Measured memory_bytes: 119500
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  int n, a;
  cin >> n >> a;
  n %= 500;

  if(n > a) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,i,x,y,z;
	scanf("%d %d %d",&a,&b,&c);
	y=0;
	for(i=a;i<=b;i++){
		x=c%i;
		if(x==0){
			y+=1;
		}
	}
	printf("%d\n",y);
	return 0;
}


Measured memory_bytes: 2716
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s,o,w;
    int n,a,b;
    cin>>s>>n;
    for(int x=0;x<n;x++){
        cin>>o>>a>>b;
        if(o=="print") cout<<s.substr(a,b-a+1)<<endl;
        if(o=="reverse")
            for(int i=a,j=b;i<j;i++,j--) swap(s[i],s[j]);
        if(o=="replace"){
            cin>>w;
            s=s.substr(0,a)+w+s.substr(b+1);
        }
    }
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a=n/100;
	int b=(n%100)/10;
	int c=n%10;
	if(a==7||b==7||c==7) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
} 

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

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int a,b,c,d;std::cin>>a>>b>>c>>d;
    std::cout<<(a+b==c+d?"Balanced":a+b>c+d?"Left":"Right")<<std::endl;
}

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

int main(){
  int n;  cin >> n;
  vector<int> c(n-1), s(n-1), f(n-1);
  for(int i=0; i<n-1; i++)
    cin >> c[i] >> s[i] >> f[i];
  
  for(int j=0; j<n-1; j++){
    int nowt = 0;
    for(int i=j; i<n-1; i++){
      nowt = ((max(nowt, s[i])-1) / f[i] + 1) * f[i] + c[i];
    }
    cout << nowt << endl;
  }

  cout << "0" << endl;

  return 0;
}


Measured memory_bytes: 3632