akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define N 10000
#define NIL -1
typedef struct node{
  int parent;
  int right;
  int left;
}Node;

Node T[N];
int n,D[N],H[N];
void setDepth(int,int);
void print(int);
int setHeight(int);
int getSibling(int);

int main(){
  int i,v,l,r,root=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    T[i].parent = NIL;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l!=NIL) T[l].parent = v;
    if(r!=NIL) T[r].parent = v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent == NIL){
      root=i;
    }
  }
  setDepth(root,0);
  setHeight(root);
  
  for(i=0;i<n;i++){
    print(i);
  }

  return 0;
}

void setDepth(int u,int d){
  if(u==NIL){
    return;
  }
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left != NIL){
    h1 = setHeight(T[u].left)+1;
  }
  if(T[u].right != NIL){
    h2 = setHeight(T[u].right)+1;
  }
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL){
    return T[T[u].parent].left;
  }
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL){
    return T[T[u].parent].right;
  }
  return NIL;
}
void print(int a){
  int deg=0;
  printf("node %d: ",a);
  printf("parent = %d, ",T[a].parent);
  printf("sibling = %d, ",getSibling(a));
  if(T[a].left != NIL) deg++;
  if(T[a].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[a]);
  printf("height = %d, ",H[a]);

  if(T[a].parent== NIL){
    printf("root\n");
  }
  else if(T[a].left == NIL && T[a].right == NIL){
    printf("leaf\n");
  }
  else printf("internal node\n");
}






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

int main() {
    int a, n, max = -1000000, min = 1000000;
    long long sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a > max) {
            max = a;
        }
        if (a < min) {
            min = a;
        }
        sum += a;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

int gcd(int a, int b);
int lcm(int a, int b);

void solve_A(){
    int n, m;
    cin >> n >> m;

    if(n <= m) cout << "Yes";
    else cout << "No";
}

void solve_B(){
    int a, b, ans = 0;
    cin >> a >> b;

    if(a > b){
        REP(i,a){
            cout << b;
        }
    }else{
        REP(i,b){
            cout << a;
        }
    }
}

void solve_C(){
    int n;
    cin >> n;
    int max_score = 0, min_score = n;
    int ctr = 0;

    int p[n];
    REP(i,n){
        cin >> p[i];

        if(max_score < p[i] || min_score < p[i]) ctr++;

        if(max_score <= p[i]) max_score = p[i];
        if(min_score >= p[i]) min_score = p[i];
    }

    cout << n - ctr + 1;

}

int main(void){
    
    
    solve_C();
    
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);

    int r = a % b;
    while(r != 0){
        a = b;  b = r;  r = a % b;
    }
    return b;
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int v[n], c[n];
    for(int i=0; i<n; i++)
        cin >> v[i];
    for(int i=0; i<n; i++)
        cin >> c[i];
    int sum=0;
    for(int i=0; i<n; i++)
    {
        if(v[i]>c[i])
            sum += v[i] - c[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
def draw_frame(w, h)
  puts "#" * w
  (h - 2).times { puts "#" + ("." * (w - 2)) + "#" }
  puts "#" * w
end

while line = gets.chomp
  break if line == "0 0"
  h, w = line.split(" ").map(&:to_i)
  draw_frame(w, h)
  puts
end

Measured memory_bytes: 8704
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define coyes cout << "Yes" << endl;
#define cono cout << "No" << endl;
#define coYes cout << "YES" << endl;
#define coNo cout << "NO" << endl;
using namespace std;
using ll = long long int;

int main() {
  int n;
  cin >> n;
  if (n % 2 == 0){
    cout << n / 2 << endl;
  }
  else {
    cout << n / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, c=0;
    cin>>n;
    c = c + n/500;
    n = n%500;
    c = c*1000;
    n = n/5;
    c = c + n*5;
    cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z,k;
    cin>>n;
    if((n>=400) && (n<=599))x = 8;    
    else if((n>=600) && (n<=799))x = 7;    
    else if((n>=800) && (n<=999))x = 6;    
    else if((n>=1000) && (n<=1199))x = 5;    
    else if((n>=1200) && (n<=1399))x = 4;    
    else if((n>=1400) && n<=1599)x = 3;    
    else if(n>=1600 && n<=1799)x = 2;    
    else if(n>=1800 && n<=1999)x = 1;
    cout<<x;    

    return 0;
}

Measured memory_bytes: 3648
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static String[] s;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		String S = nextString();
		s = new String[S.length()];

		ArrayList<Integer> R = new ArrayList<>();
		ArrayList<Integer> G = new ArrayList<>();
		ArrayList<Integer> B = new ArrayList<>();

		for(int i=0;i<s.length;i++){
			s[i]=S.substring(i,i+1);
			if("R".equals(s[i])){
				R.add(i);
			}
			if("G".equals(s[i])){
				G.add(i);
			}
			if("B".equals(s[i])){
				B.add(i);
			}
		}

		long ans =0;
//		for(int r:R){
//			for(int g:G){
//				for(int b:B){
//					int i=Math.min(Math.min(r, g),b);
//					int k=Math.max(Math.max(r, g),b);
//					int j = r+g+b-i-k;
//					if(j-i!=k-j){
//						ans++;
////						System.out.println(s[i]+":"+s[j]+":"+s[k]);
//					}
//
//				}
//			}
//		}
//		System.out.println(ans);
		ans=R.size()*G.size()*B.size();
		BigInteger x = BigInteger.valueOf(R.size()).multiply(BigInteger.valueOf(G.size())).multiply(BigInteger.valueOf(B.size()));
		BigInteger s1 = BigInteger.valueOf(1);
		for(int i=1;i<N;i++){
			for(int k=i;k+i<N;k++){
				if(!s[k-i].equals(s[k]) && !s[k-i].equals(s[k+i]) &&!s[k].equals(s[k+i])){
					x = x.subtract(s1);
				}
			}
		}
//
//		ans+=rgb(R,G,B);
//		ans+=rgb(R,B,G);
//		ans+=rgb(G,R,B);
//		ans+=rgb(G,B,R);
//		ans+=rgb(B,G,R);
//		ans+=rgb(B,R,G);
//
//



		System.out.println(x.longValue());

	}


	public static long rgb(TreeSet<Integer>R,TreeSet<Integer>G,TreeSet<Integer>B){

		long ans =0;
		for(int i:R){
			for(int j:G.tailSet(i)){
				Set<Integer> t = B.tailSet(j+j-i-1);
				ans+=t.size();
			}
		}
		return ans;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 44468
#include <stdio.h>
#include <string.h>

int max(int a, int b){
  if(a>b){
    return a;
  }else{
    return b;
  }
}

int main(void){
  int N,tmp;
  int cnts[100005] = {};

  scanf("%d",&N);
  for(int i = 0; i < N; i++){
    scanf("%d",&tmp);
    cnts[tmp]++;
  }

  int ans = 0;
  for(int i=1; i < 100003; i++){
    tmp = cnts[i-1]+cnts[i]+cnts[i+1];
    ans = max(ans,tmp);
  }

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

}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
	int rooms[4][3][10], counts;
	
	// initialize
	for(int i = 0;i < 4;i++){
		for(int j = 0;j < 3;j++){
			for(int k = 0;k < 10;k++){
				rooms[i][j][k] = 0; 
			}
		}
	}
	
	scanf("%d", &counts);
	for(int i = 0;i<counts;i++){
		int building, floor, room, person; 
		scanf("%d %d %d %d", &building, &floor, &room, &person);
		rooms[building-1][floor-1][room-1] += person;
	}
	
	
	//output
	for(int i = 0;i < 4;i++){
		for(int j = 0;j < 3;j++){
			for(int k = 0;k < 10;k++){
				printf(" %d", rooms[i][j][k]);
			}
			printf("\n");
		}
		if(i != 3){
			for(int l = 0;l < 20;l++) printf("#");
			printf("\n");
		}
	}
	
	return 0;
}


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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 200000

int L;
long long A[MAX];

long long dp[MAX + 1][5];

int main() {
	cin >> L;
	for( int i = 0; i < L; i++ ) {
		cin >> A[i];
	}

	for( int i = 0; i < L; i++ ) {
		int zero_c = 0;
		if( A[i] == 0 ) {
			zero_c = 2;
		}
		dp[i + 1][0] = dp[i][0] + A[i];
		dp[i + 1][1] = min( dp[i][0], dp[i][1] ) + A[i] % 2 + zero_c;
		dp[i + 1][2] = min( dp[i][2], min( dp[i][0], dp[i][1] ) ) + (A[i] + 1) % 2;
		dp[i + 1][3] = min( dp[i][3], min( dp[i][2], min( dp[i][0], dp[i][1] ) ) ) + A[i] % 2 + zero_c;
		dp[i + 1][4] = min( dp[i][4], min( dp[i][3], min( dp[i][2], min( dp[i][0], dp[i][1] ) ) ) ) + A[i];
	}
	long long ans = INF;
	for( int i = 0; i < 5; i++ ) {
		ans = min( ans, dp[L][i] );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9728
#define ll long long int
#define pb push_back
#define mp make_pair
#include <bits/stdc++.h>
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	ll t=1,r,n,a,b,c,x,y,sum,cnt,i,j,k,m,l,q,maxx,minn,temp,ans,flag,z,h,w,p,ts;
	
	string str,ttr;
	long double dans;
	
	
	
//	cin >> t;

	
	for(ts=1;ts<=t;ts++)
	{
	    flag=0;sum=0;cnt=0;ans=0;maxx=0,minn=99999999999; x=0;y=0;temp=0;
	    
	    cin >>k>> n; ll arr[n];
	    
	    for(i=0;i<n;i++)
	    cin>>arr[i];
	    
	    for(i=1;i<n;i++)
	    {   
	        x=arr[i]-arr[i-1];
	        sum=sum+arr[i]-arr[i-1];
	        
	        maxx=max(maxx,x);
	    }
	   
	   x=k-arr[n-1]+arr[0];
	   sum=sum+x;
	   maxx=max(maxx,x);
	   sum=sum-maxx;
	   
	   cout<<sum<<"\n";
	    
	    
	    
	    
	  // cout << ans <<"\n";
	}
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        int[] train = new int[2];
        int[] bus = new int[2];
        Scanner sc = new Scanner(System.in);
        
        for(int i = 0 ; i < 2;i++){
            train[i] = sc.nextInt();
        }
        for(int j = 0 ; j < 2; j++){
            bus[j] = sc.nextInt();
        }
        System.out.println(Math.min(train[0],train[1]) + Math.min(bus[0],bus[1]));
    }
}


Measured memory_bytes: 23764
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long int lis[200005]={0},rui[200005]={0};
int main(){
    long long int N;
    cin>>N;
    for(int i=0;i<N;i++)cin>>lis[i];
    for(int i=0;i<N;i++){
        lis[N+i]=lis[i];
    }
    for(int i=0;i<N*2+1;i++){
        if(i==0)rui[i]=lis[i];
        else rui[i]=rui[i-1]+lis[i];
    }
    long long int maxans=0;
    rui[2*N]=1000000000000000000;rui[2*N+1]=1000000000000000000;rui[2*N+2]=1000000000000000000;rui[2*N+3]=1000000000000000000;
    for(int i=0;i<N;i++){
        long long int l=0,r=10000000000000000,mid=(l+r)/2;
        for(int j=0;j<55;j++){
            mid=(l+r)/2;
            long long int ll=i,rr=2*N+1,midmid=(ll+rr)/2;
            for(int k=0;k<18;k++){
                midmid=(ll+rr)/2;
                if(i!=0){
                    if(rui[midmid]-rui[i-1]>=mid)rr=midmid;
                    else ll=midmid;
                }
                else if(rui[midmid]>=mid)rr=midmid;
                else ll=midmid;
            }
            int memo=rr+1;
            ll=rr,rr=2*N+1,midmid=(ll+rr)/2;
            for(int k=0;k<18;k++){
                midmid=(ll+rr)/2;
                if(rui[midmid]-rui[memo-1]>=mid)rr=midmid;
                else ll=midmid;
            }
            memo=rr+1;
            ll=rr,rr=2*N+1,midmid=(ll+rr)/2;
            for(int k=0;k<18;k++){
                midmid=(ll+rr)/2;
                if(rui[midmid]-rui[memo-1]>=mid)rr=midmid;
                else ll=midmid;
            }
            if(rr<2*N&&rr-i<N)l=mid;
            else r=mid;
        }
        maxans=max(maxans,mid);
    }
    cout<<maxans<<endl;
    return 0;
}

Measured memory_bytes: 4284
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	wtr := bufio.NewWriter(os.Stdout)
	for bits := 0; bits < (1 << uint(n)); bits++ {
		fmt.Fprint(wtr, bits, ":")
		for j := 0; j < n; j++ {
			if (bits & (1 << uint(j))) != 0 {
				fmt.Fprint(wtr, " ", j)
			}
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}



Measured memory_bytes: 6152
#include <stdio.h>


int main()
{
    int in;
    int higher, lower;

    scanf("%d", &in);

    higher = in/100;
    lower = in - higher*100;

    // AMBIGUOUS
    if ((1 <= higher && higher <= 12) && (1 <= lower && lower <= 12))
    {
        puts("AMBIGUOUS");
        return 0;
    }

    // NA
    if ((higher == 0 || 13 <= higher) && (lower == 0 || 13 <= lower))
    {
        puts("NA");
        return 0;
    }
    
    // MMYY
    if ((1 <= higher && higher <= 12) && (lower == 0 || 13 <= lower))
    {
        puts("MMYY");
        return 0;
    }

    // YYMM
    puts("YYMM");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
int a,b;
scanf("%d %d",&a ,&b);
if (a<b){
printf("a < b\n");
}
else if (a>b) {
printf("a > b\n");
}
else{
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 580
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using base = complex<double>;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define M2 998244353
#define ll long long
#define pll pair<long, long>
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define ff first
#define ss second
#define pb push_back
#define db pop_back
#define mp make_pair
#define mt make_tuple
#define g(a, b) get<a>(b)
#define INF (ll)1e18 + 100
#define vl vector<ll>
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define all(v) v.begin(), v.end()
#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
#define INT_SIZE 32
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
ll powM(ll x, ll y, ll m)
{
    ll ans = 1, r = 1;
    x %= m;
    while (r > 0 && r <= y)
    {
        if (r & y)
        {
            ans *= x;
            ans %= m;
        }
        r <<= 1;
        x *= x;
        x %= m;
    }
    return ans;
}
ll modI(ll a, ll m)
{
    ll m0 = m, y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

ll logint(ll x, ll y)
{
    ll ans = 0;
    ll a = 1;
    for (ll i = 0; i <= x; i++)
    {
        if (x < a)
        {
            return ans;
        }
        ans++;
        a *= y;
    }
    return -1;
}
ll extended(ll a, ll b, ll &x, ll &y)
{
    if (a == 0)
    {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = extended(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll lcm(ll x, ll y) {
    return (x * y) / (__gcd(x, y));
}

void solve() {
    string s;
    cin >> s;
    REP(i, 0, s.size()) {
        if (s[i] == ',') {cout << " ";}
        else {
            cout << s[i];
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("b1.in", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ll ntc;
    // cin >> ntc;
    ntc = 1;
    REP(tc, 1, ntc + 1)
    {
        // cout << "Case #" << tc << ": ";
        solve();
    }
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N,A,B,C,D;
string S;

signed main(){
	cin>>N>>A>>B>>C>>D>>S;
	int pos=INF,pos2=INF;
	for(int i=A-1;i<S.size()-1;i++){
		if(S[i]=='#'&&S[i+1]=='#'){
			pos=i;
			break;
		}
	}
	for(int i=B-1;i<S.size()-2;i++){
		if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.'){
			pos2=i;
			break;
		}
	}
	if(C<D){
		for(int i=A-1;i<C-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		for(int i=B-1;i<D-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		cout<<"Yes"<<endl;
	}
	else{
		for(int i=A-1;i<C-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		for(int i=B-1;i<D-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		for(int i=B-2;i<D-1;i++){
			if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.'){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 640
#AOJのコース用からJOI2006用に編集

L=input().split( )
a=[int(L[0]),1,0]#gcd途中の余り、その余りをka+lbと表したk,l
b=[int(L[1]),0,1]

while a[0]%b[0]!=0:
    k=a[0]//b[0]

    c=b[0]
    c1=b[1]
    c2=b[2]

    a[1]-=(k*b[1])
    a[2]-=(k*b[2])

    b[0]=a[0]%b[0]
    b[1]=a[1]
    b[2]=a[2]

    a[0]=c
    a[1]=c1
    a[2]=c2
    #print(a,b)
k=a[0]//b[0]

c=b[0]
c1=b[1]
c2=b[2]

a[1]-=(k*b[1])
a[2]-=(k*b[2])

b[0]=a[0]%b[0]
b[1]=a[1]
b[2]=a[2]

a[0]=c
a[1]=c1
a[2]=c2
#print(a,b)
print(a[1],a[2])



Measured memory_bytes: 5612
#include <stdio.h>
int main()
{

  int W,H,x,y,r;
  scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
  if(x >= r && H-x >= r && y >= r && H-y >= r) printf("Yes\n");
  else printf("No\n");
 
  return 0;

}

Measured memory_bytes: 584
#include <iostream>

using namespace std;

int main() {
  int a = 0;
  int b = 0;
  for (int i = 0; i < 3; i++) {
    int x;
    cin >> x;
    if (x == 5) a++;
    else if (x == 7) b++;
  }
  if (a == 2 && b == 1) cout << "YES\n";
  else cout << "NO\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n+1),b(n+1),c(n+1);
    vector<vector<ll>> vals(n, vector<ll>(3));
    for (int i = 0; i < n; ++i) {
        // cin >> a[i] >> b[i] >> c[i];
        cin >> vals[i][0] >> vals[i][1] >> vals[i][2];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(3, 0));

    // init
    for (int i = 0; i < 3; ++i) {
        dp[0][i] = 0;
    }

    dp[1][0] = vals[0][0];
    dp[1][1] = vals[0][1];
    dp[1][2] = vals[0][2];

    for(int dp_i = 2; dp_i <= n; ++dp_i) {
        for(int ci = 0; ci < 3; ci++) {
            vector<ll> candidates;
            for(int ii = 0; ii < 3; ii++) {
                if (ci != ii) {
                 candidates.push_back(dp[dp_i-1][ii] + vals[dp_i-1][ci]);
                }
            }
            // refresh
            dp[dp_i][ci] = *max_element(candidates.begin(), candidates.end());
        }
    }

    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;

    return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    string s; cin >> s;
    vvll dp(n+1, vll(n+1, 0));
    rep(i, 1, n+1) rep(j, 1, n+1) {
        if (s[i-1] == s[j-1]) dp[i][j] = dp[i-1][j-1]+1;
    }
    // REP(i, n+1) {
    //     REP(j, n+1) cout << dp[i][j] << ' ';
    //     cout << '\n';
    // }
    ll ans = 0;
    REP(i, n+1) {
        rep(j, i+1, n+1) {
            if (dp[i][j] > 0) {
                if (j - dp[i][j] >= i) chmax(ans, dp[i][j]);
                else {
                    ll tmp = dp[i][j] - (j-i);
                    chmax(ans, min(dp[i][j]-tmp, dp[i][i]-tmp));
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


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

const char t[]="hi";
char str[15];

int main()
{
    scanf("%s",str);
    int n=strlen(str);
    if(n%2)return 0*printf("No\n");
    for(int i=0;i<n;i++)
        if(str[i]!=t[i%2])
            return 0*printf("No\n");
    return 0*printf("Yes\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
  int i;
  int n,sum=1,ans=1;
  cin>>n;
  vector<int> d(n),D;
  for(i=0;i<n;++i)
    cin>>d.at(i);
  sort(d.begin(),d.end());
  //for(i=0;i<n;++i)cout<<d.at(i)<<' ';
  
  for(i=0;i<n-1;++i){
    if(d.at(i)!=d.at(i+1))
      D.push_back(d.at(i));
  }
  D.push_back(0);
  cout<<D.size()<<endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
long long mod_pow(long long x, long long n, long long mod)
{
    if (n == 0)
        return 1;
    long long res = mod_pow(x * x % mod, n / 2, mod);
    if (n & 1)
        res = res * x % mod;
    return res;
}
int main()
{
    string s;
    cin >> s;
    vl ss;
    rp(i, 0, s.size()) ss.push_back(s[i] - '0');
    ll sss[s.size()];
    sss[s.size() - 1] = ss[s.size() - 1];
    pr(i, 0, s.size() - 1)
    {
        sss[i] = (sss[i + 1] + ss[i] * mod_pow(10, s.size() - i - 1, 2019));
        sss[i] %= 2019;
    }
    sort(sss, sss + s.size());
    //ca(s.size(), sss);
    ll ans = 0;
    ll t = 1;
    rp(i, 0, s.size() - 1)
    {
        if (sss[i] == sss[i + 1])
        {
            t++;
        }
        else
        {
            if (t >= 2)
            {
                ans += t * (t - 1) / 2;
                if (sss[i] == 0)
                    ans += t;
            }
            else
            {
                if (sss[i] == 0)
                    ans++;
            }
            t = 1;
        }
    }
    if (t >= 2)
    {
        ans += t * (t - 1) / 2;
    }
    ce(ans);
}

Measured memory_bytes: 6608
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
const int nmax = 200001;
vector<int>graph[nmax];
vector<bool>visited(nmax);

int main(){
    int n,m;
    cin >> n >> m;
    set<int>s;
    REP(i,m){
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
        if(b==n){
            s.insert(a);
        }
    }
    for(int v:graph[1]){
        if(s.find(v)!=s.end()){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
   
    cout <<"IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 16624
/*input
3 1
10 20 10
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
    os << x << " ";
  }
  return os;
}

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

/******************************** START *********************************/
const int N = 100005;

int main()
{
  ifalse;
  int n, k;
  cin >> n >> k;
  vector < int > v(n);
  cin >> v;

  int dp[n + 1] = {0};
  for(int i = 1; i < n; i ++) {
    dp[i] = dp[i - 1] + abs(v[i] - v[i - 1]);
    int j = i - 2;
    int cnt = 1;
    while(j >= 0 and cnt < k) {
      dp[i] = min(dp[i], dp[j] + abs(v[i] - v[j]));
      cnt ++;
      j --;
    }
  }
  cout << dp[n - 1], nl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
  int a[3];
  int i,j;
  int temp;

  for (i=0; i<3; i++) {
	scanf("%d",&a[i]);
  }

  for (i=0; i<3-1; i++) {
	for (j=i+1; j<3; j++) {
	  if (a[i]>a[j]) {
		temp=a[i];
		a[i]=a[j];
		a[j]=temp;
	  }
	}
  }
  for (i=0; i<2; i++) {
	printf("%d ",a[i]);
  }
  printf("%d\n",a[2]);
  return 0;
}

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

int N;

int main() {
  cin >> N;
  int prev = -1, mode = 0, res = 1;
  for(int i = 0; i < N; ++i) {
    int A; cin >> A;
    if(prev > 0) {
      if(prev < A) {
        if(mode == -1) { ++res; mode = 0; }
        else mode = 1;
      } else if(prev > A) {
        if(mode == 1) { ++res; mode = 0; }
        else mode = -1;
      }
    }
    prev = A;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,x = inpl()
print(b//x - (a-1)//x)

Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    std::deque<int> deq;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    int count=0;
    for (int j=1;j<n-1;j++) {
        if ( (deq[j-1]<deq[j]&&deq[j]<deq[j+1])||(deq[j-1]>deq[j]&&deq[j]>deq[j+1]) ) {
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int k,x,a,b,lo=-1000000,hi=1000000;
  scanf("%d %d",&k,&x);
  a=x-k+1;
  b=x+k-1;
  if(a>=lo &&  b<=hi){
    for(int i=0;i<((k*2)-1);i++){
      printf("%d ",a);
      a++;
    }
  }
  else if(a< lo)
    {
     for(int i=0;i<((k*2)-1);i++){
       printf("%d ",lo);
       lo++;  
     }
    }
  else if(a>hi)
    {
      for(int i=0;i<((k*2)-1);i++){
	printf("%d" ,hi);
	hi++;  
      }
    }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238462643383279

int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    long double H,M,red,s,ans;
    H=h*30;
    M=m*6;
    H=H+M/12;
    s=abs(H-M);
    red=cos(s*PI/180);
    ans=((a*a+b*b)-2*a*b*red);
    ans=sqrt(ans);
   cout<<fixed<<showpoint;
   cout<<setprecision(15);
   cout<<ans<<endl;
    return 0;
}

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


vector<vector<ll>> g;
vector<ll> depth;
bool flag = false;

void dfs(int pos, int dep){
  if(depth[pos] >= 0) {
      if(depth[pos] != dep) flag = true;
      return;
  }
  depth[pos] = dep;
  for(auto x:g[pos]) dfs(x,dep^1);
}

int main(){
  ll n;cin>>n;
  vector<string> s(n);
  rep(i,n) cin>>s[i];
  vector<vector<ll>> dist(n, vector<ll>(n, MAX));
  g.resize(n);
  rep(i,n){
    rep(j,n) if(s[i][j] == '1') {
        g[i].push_back(j);
        dist[i][j] = 1;
    }
  }
  //二部グラフ判定
  depth.resize(n, 0);
  rep(i,n) depth[i] = -1;
  dfs(0,0);
  if(flag){
      puts("-1");
      return 0;
  }
  //warshall_floyd法
  rep(i,n) dist[i][i]=0;
  rep(k,n)rep(i,n)rep(j,n) dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
  ll ans=0;
  rep(i,n) ans = max(ans,*max_element(dist[i].begin(),dist[i].end()));
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

typedef long long  ll;

// void calcualtePatern(int count[], bool flag[], long int *ans, int check, int *a)
// {
// 	*a++;
// 		printf("%d\n", *a);
// 	int num=1, thr=0;
// 	for(int i=0; i<5; i++){
// 		if(flag[i]){
// 			// printf("%d ", i);
// 			thr ++;
// 			num = num * count[i];
// 		}
// 	}
// 	if(thr == 3){
// 		*ans += num;
// 	}
// 		// printf("\n");
// 	check ++;
// 	if(check==5){
// 		return;
// 	}
// 	calcualtePatern(count, flag, ans, check, a);
// 	flag[check] = true;
// 	calcualtePatern(count, flag, ans, check, a);
// }


int main()
{
	int N, check=-1;
	ll ans=0, count[5]={};
	char ch[20];
	int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
	int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
	int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%s", ch);
		if(ch[0] == 'M'){
			count[0]++;
		}
		else if(ch[0] == 'A'){
			count[1]++;
		}
		else if(ch[0] == 'R'){
			count[2]++;
		}
		else if(ch[0] == 'C'){
			count[3]++;
		}
		else if(ch[0] == 'H'){
			count[4]++;
		}
	}
	
	for(int i=0; i<10; i++){
		ans += count[P[i]]*count[Q[i]]*count[R[i]];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0) break;
        if(x<y){
            printf("%d %d\n",x,y);
        }
        else{
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}


Measured memory_bytes: 2560
//
// Created by kapildd on 12/23/17.
//

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int n = s.size(), best = n;
    for(int i=1; i<n; i++) {
        if(s[i] != s[i-1]) {
            best = min(best, max(i, n-i));
        }
    }
    cout << best << endl;
    return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  vector<vector<int>> co(n);
  rep(i, m) {
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--;
    to[u].push_back(v);
    co[u].push_back(c);
  }
  rep(i, n - 1) {
    to[i + 1].push_back(i);
    co[i + 1].push_back(0);
  }
  int start = 0; // スタート
  int end = n - 1; // ゴール
  vector<P> dist(n, P(LINF, -1)); // P(dist, from)
  priority_queue<P, vector<P>, greater<P>> q; // P(cost, v)
  dist[start] = P(0, -1);
  q.push(P(0, start));
  while (!q.empty()) {
    P p = q.top();
    q.pop();
    int u = p.second;
    if (dist[u].first < p.first) continue;
    rep(i, to[u].size()) {
      int v = to[u][i], c = co[u][i];
      if (dist[v].first > dist[u].first + c) {
        dist[v] = P(dist[u].first + c, u);
        q.push(P(dist[v].first, v));
      }
    }
  }
  // 最小コストを表示
  if (dist[end].first == LINF)
    cout << -1 << endl;
  else
    cout << dist[end].first << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 13684
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[100005], b[100005], c[100005], n;
    int dp[100005][5];
    memset(dp, 0, sizeof(dp));
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=3; j++){
            if(j==1){
                dp[i][j]=max(a[i]+dp[i-1][j+1],a[i]+dp[i-1][j+2]);
            }else if(j==2){
                dp[i][j]=max(b[i]+dp[i-1][j+1],b[i]+dp[i-1][j-1]);
            }else{
                dp[i][j]=max(c[i]+dp[i-1][j-1],c[i]+dp[i-1][j-2]);
            }
        }
    }
    int resp=-1;
    for(int i=1; i<=3; i++){
        resp=max(dp[n][i], resp);
    }
    cout << resp << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin>>N;
    vl H(N + 1);
    rep(i, N) cin >> H[i];

    stack<ll> st;
    vl left(N + 1);

    ll ans = 0;
    rep(i,N+1){
        while(!st.empty() and H[st.top()] >= H[i]){
            chmax(ans, (i - left[st.top()]) * H[st.top()]);
            st.pop();
        }
        left[i] = st.empty() ? 0 : (st.top() + 1);
        st.emplace(i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 5144
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int T;
    cin >> T;
    while (T--) {
        int t;
        cin >> t;
        cout <<( a[(lower_bound(a, a + n, t)-a)] == t )<< endl;
    }
    return 0;
}


Measured memory_bytes: 3460
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+7;
//ll a[MAX];
int main()
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	string s;
 	cin>>s;
 	if(s=="ABC")cout<<"ARC";
 	else cout<<"ABC";
 	
 	
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9+7;

int main(){
	int N,M,K; cin >> N >> K >> M;
	vector<int> A(M);
	repp(i,0,M) cin >> A[i];
	if(N < K) return cout << 0 << endl, 0;
	bool c = 0;
	repp(i,0,M-K){
		vector<int> b(K);
		repp(j,0,K){
			if(b[A[i+j]-1]) break;
			b[A[i+j]-1] = 1;
			if(j+1 == K) c = 1;
		}
	}
	LL ans = N-M+1;
	repp(i,0,N-M) (ans *= K) %= mod;
	if(c) return cout << ans << endl, 0;
	int l = 0, r = 0;
	{
		vector<int> b(K,0);
		repp(i,0,M){
			if(b[A[i]-1]) break;
			++l;
			b[A[i]-1] = 1;
		}
	}
	{
		vector<int> b(K,0);
		repm(i,M-1,-1){
			if(b[A[i]-1]) break;
			++r;
			b[A[i]-1] = 1;
		}
	}
	if(l == M){
		LL v = 1, w = 1;
		repm(i,K,K-M) w = w*i%mod;
		for(LL i = mod-2 ; i > 0 ; i /= 2){
			if(i&1) v = v*w%mod;
			w = w*w%mod;
		}
		vector<LL> dp0(K,0),dp1(K,0);
		dp0[1] = K;
		if(M == 1) dp1[1] = 1;
		repp(i,1,N){
			vector<LL> nx0(K,0),nx1(K,0);
			LL x = 0, y = 0;
			repm(j,K-1,0){
				(x += dp0[j]) %= mod;
				nx0[j] = (x+dp0[j-1]*(K-j+1))%mod;
				(y += dp1[j]) %= mod;
				nx1[j] = (y+dp1[j-1]*(K-j+1))%mod;
				if(j >= M) (nx1[j] += nx0[j]*v) %= mod;
			}
			swap(dp0,nx0); swap(dp1,nx1);
		}
		repp(i,1,K) (ans -= dp1[i]) %= mod;
		cout << (ans+mod)%mod << endl;
		return 0;
	}
	vector<vector<LL>> dpl(N-M+1,vector<LL>(K,0)),dpr(N-M+1,vector<LL>(K,0));
	dpl[0][l] = dpr[0][r] = 1;
	repp(i,0,N-M){
		LL x = 0, y = 0;
		repm(j,K-1,0){
			(x += dpl[i][j]) %= mod;
			(dpl[i+1][j] += x+dpl[i][j-1]*(K-j+1)) %= mod;
			(y += dpr[i][j]) %= mod;
			(dpr[i+1][j] += y+dpr[i][j-1]*(K-j+1)) %= mod;
		}
		dpl[i][0] = x;
		dpr[i][0] = y;
	}
	repp(j,1,K){
		(dpl[N-M][0] += dpl[N-M][j]) %= mod;
		(dpr[N-M][0] += dpr[N-M][j]) %= mod;
	}
	repp(i,0,N-M+1){
		(ans -= dpl[i][0]*dpr[N-M-i][0]) %= mod;
	}
	cout << (ans+mod)%mod << endl;
	return 0;
}


Measured memory_bytes: 158336
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t , p;
	double ans = 999999;
	double a , b , x;
	cin >> t;
	cin >> a >> b;
	for(int i = 1 ; i <= t ; i++)
	{	
		cin >> x;
		if(abs(a-x*0.006 - b) <= ans)
		{
			ans = abs(a-x*0.006 - b);
			p = i;
		}
	 } 
	 cout << p << endl;
	return 0;
 } 

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

const int maxn = 1e5 + 5;
long long dp[maxn][4];
int a[maxn], b[maxn], c[maxn];

int main(int argc, char const *argv[])
{
//	freopen("in.txt", "r", stdin);
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
	}
	dp[1][1] = a[1], dp[1][2] = b[1], dp[1][3] = c[1];
	for(int i=2; i<=n; i++){
		dp[i][1] = max(dp[i][1], max(dp[i-1][2]+a[i], dp[i-1][3]+a[i]));
		dp[i][2] = max(dp[i][2], max(dp[i-1][1]+b[i], dp[i-1][3]+b[i]));
		dp[i][3] = max(dp[i][3], max(dp[i-1][1]+c[i], dp[i-1][2]+c[i]));
	}
	printf("%lld\n", max(dp[n][1], max(dp[n][2], dp[n][3])));

	return 0;
}

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

using namespace std;

int main(){
  int n, min, tmp, count;
  count = -1;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  bool odd = false;
  while(!odd){
    count++;
	for(int i=0;i<n;i++){
      if(a[i]%2!=0)odd = true;
	  a[i] /= 2;
	}
  }
  cout << count << endl;  
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX1 100000
#define MAX2 50000
void Search(int *,int);

int count=0;
 int right=0,left=0,mid=0;
int m;
int main()
{
  int n,i,j;
  int s[MAX1],t[MAX2];

  //ここからscan
  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      scanf("%d",&s[i]);
    }
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&t[i]);
    }
  //ここまで
  for(i=0;i<n;i++)
    {
      Search(s,t[i]);
    }
  printf("%d\n",count);
  return 0;
}

void Search(int *A,int key)
{
  left = 0;
  right = m;
  while(left<right)
    {
      mid = (left + right)/2;
      if(key==A[mid])
	{
	  count+=1;
	  break;
	}
      else if(key > A[mid])
	{
	  left = mid + 1;
	}
      else if(key < A[mid])
	{
	  right = mid;
	}
    }
}

Measured memory_bytes: 1184
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let a = (100 * n + 108 - 1) / 108;
    let b = (100 * (n + 1) + 108 - 1) / 108;
    if a < b {
        println!("{}", a);
    } else {
        println!(":(");
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] arr = new int[n + 1];
		arr[0] = x;
		for (int i = 1; i <= n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int[] arr2 = new int[n];
		for (int i = 0; i < n; i++) {
			arr2[i] = arr[i +1] - arr[i];
		}
		Arrays.sort(arr2);
		int d = arr2[0];
		for (int i = 1; i < n; i++) {
			if (arr2[i - 1] == arr2[i]) {
				continue;
			}
			d = cd(arr2[i], d);
		}
		System.out.println(d);
	}
	
	public static int cd(int x, int y){
		if (x % y == 0) {
			return y;
		} else {
			return cd(y, x%y);
		}
	}
}

Measured memory_bytes: 50460
#include<bits/stdc++.h>
#define int long long int
#define frwd(i,a,b,j) for(int i=a;i<b;i+=j)
#define rev(i,a,b,j) for(int i=a;i>=b;i-=j)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define tr(container, it) \
for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int > > 
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define INF LLONG_MAX
#define mod 1000000007
using namespace std;
void solve()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	frwd(i,0,n,1) cin>>a[i];
	vector<int > dp(n+1,INF);
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(a[1]-a[0]);
	frwd(i,3,n+1,1)
	{
		frwd(j,1,k+1,1)
		{
			if(j<i) dp[i]=min(dp[i],dp[i-j]+abs(a[i-1]-a[i-1-j]));
		}
	}
	//frwd(i,0,n+1,1) cout<<dp[i]<<endl;
	cout<<dp[n];
}
signed main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	int t;
	//cin>>t;
	t=1;	
	while(t--)
	{
		solve();
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>

typedef struct {
  double x, y;
} Point;

void print(Point p){ printf("%.8f %.8f\n", p.x, p.y); }

void plot(int n, Point p1, Point p2){
  Point s, t, u;
  double th = 60.0*(acos(-1)/180.0);
  if ( n == 0 ) return;
  s.x = (2.0 * p1.x + 1.0 * p2.x)/3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y)/3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x)/3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y)/3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y ) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y ) * cos(th) + s.y;
  
  plot(n-1, p1, s);
  print(s);
  plot(n-1, s, u);
  print(u);
  plot(n-1, u, t);
  print(t);
  plot(n-1, t, p2);
}

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

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  print(p1);
  plot(n, p1, p2);
  print(p2);

  return 0;
}




Measured memory_bytes: 2056