akhauriyash/Code-Regression huggingface dataset:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = rs()
print('Yes' if N == N[::-1] else 'No')

Measured memory_bytes: 63084
#include <cmath>
#include <iostream>
#include <vector>

inline uint32_t diff(uint32_t x, uint32_t y) {
  return ((x > y) ? x - y : y - x);
}

uint32_t dfs(const std::vector<uint32_t>& bamboo, uint32_t A, uint32_t B,
             uint32_t C, uint32_t pos = 0, uint32_t a = 0, uint32_t b = 0,
             uint32_t c = 0, uint32_t penalty = 0) {
  if (pos == bamboo.size()) {
    return (a * b * c > 0) ? diff(A, a) + diff(B, b) + diff(C, c) + penalty
                           : -1;
  }

  uint32_t min_cost = -1;
  min_cost =
      std::min(min_cost, dfs(bamboo, A, B, C, pos + 1, a, b, c, penalty));
  min_cost = std::min(min_cost, dfs(bamboo, A, B, C, pos + 1, a + bamboo[pos],
                                    b, c, penalty + (a > 0) * 10));
  min_cost =
      std::min(min_cost, dfs(bamboo, A, B, C, pos + 1, a, b + bamboo[pos], c,
                             penalty + (b > 0) * 10));
  min_cost = std::min(min_cost, dfs(bamboo, A, B, C, pos + 1, a, b,
                                    c + bamboo[pos], penalty + (c > 0) * 10));

  return min_cost;
}

int main() {
  uint32_t N = 0, A = 0, B = 0, C = 0;
  std::cin >> N >> A >> B >> C;
  std::vector<uint32_t> bamboo(N);
  for (auto&& b : bamboo) std::cin >> b;

  std::cout << dfs(bamboo, A, B, C) << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
//#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
#define int long long

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
/*
#pragma comment(linker, "/STACK: 20000000005")
*/


using namespace std;

const int N = 200005, MOD = 998244353;

int n;

main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    double x = n;
    x /= 3.0;
    x = x * x * x;
    printf ("%.6f\n", x);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int sum = 0;
		int A[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			sum += A[i];
		}
		sc.close();
		if (sum >= H) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 50700
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

int main() {

	int i, j;
	deque <int> n;

	for(i=0; i<5; i++) {
		cin >> j;
		n.push_back(j);
	}

	sort(n.begin(), n.end());

	for(i=4; i>0; i--) {
		cout << n[i] << " ";
	}

	cout << n[i] << endl;

	return 0;

}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101010];
int dp[101010], dp2[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < n; i++){
		if(dp[i+1] == 0) dp[i+1] = a[i];
		else dp[i+1] = __gcd(dp[i+1],a[i]);
		dp[i+2] = dp[i+1];
	}
	for(int i = n-1; i >= 0; i--){
		if(dp2[i+1] == 0) dp2[i+1] = a[i];
		else dp2[i+1] = __gcd(dp2[i+1], a[i]);
		dp2[i] = dp2[i+1];
	}
	
	int ma = 0;
	for(int i = 0; i < n; i++){
		chmax(ma, __gcd(dp[i],dp2[i+2]));
	}
	cout << ma << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N;
    cin>>N;
    ll h[N];
    vector<ll> dp(N,INF);
    for(ll i=0;i<N;i++) cin>>h[i];
    dp[0]=0;
    for(ll i=1;i<N;i++){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[N-1]<<endl;

}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
#include <climits>
#include <queue>
using namespace std;

class Edge{
public:
    int to, cap, cost, rev;
    Edge(){};
    Edge(int to0, int cap0, int cost0){to = to0; cap = cap0, cost = cost0;}
    Edge(int to0, int cap0, int cost0, int rev0){to = to0; cap = cap0; cost = cost0; rev = rev0;}
};

int minCostFlow(const vector<vector<Edge> >& edges0, int source, int sink, int flow)
{
    int n = edges0.size();
    vector<vector<Edge> > edges(n);
    for(int i=0; i<n; ++i){
        for(unsigned j=0; j<edges0[i].size(); ++j){
            const Edge& e = edges0[i][j];
            edges[i].push_back(Edge(e.to, e.cap, e.cost, edges[e.to].size()));
            edges[e.to].push_back(Edge(i, 0, -e.cost, edges[i].size()-1));
        }
    }

    vector<int> h(n, 0);
    vector<int> prevV(n);
    vector<int> prevE(n);

    int ret = 0;
    while(flow > 0){
        vector<int> dist(n, INT_MAX);
        dist[source] = 0;
        priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
        q.push(make_pair(0, source));

        while(!q.empty()){
            pair<int, int> p = q.top();
            q.pop();
            int v = p.second;
            if(dist[v] < p.first)
                continue;
            for(unsigned i=0; i<edges[v].size(); ++i){
                Edge e = edges[v][i];
                if(e.cap > 0 && dist[v] + e.cost + h[v] - h[e.to] < dist[e.to]){
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevV[e.to] = v;
                    prevE[e.to] = i;
                    q.push(make_pair(dist[e.to], e.to));
                }
            }
        }
        if(dist[sink] == INT_MAX){
            return -1;
        }
        for(int i=0; i<n; ++i)
            h[i] += dist[i];

        int g = flow;
        for(int i=sink; i!=source; i=prevV[i])
            g = min(g, edges[prevV[i]][prevE[i]].cap);
        for(int i=sink; i!=source; i=prevV[i]){
            Edge& e = edges[prevV[i]][prevE[i]];
            e.cap -= g;
            edges[i][e.rev].cap += g;
        }
        flow -= g;
        ret += g * h[sink];
    }
    return ret;
}

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

	vector<vector<int> > a(n, vector<int>(2));
	for(int i=0; i<n; ++i)
		cin >> a[i][0] >> a[i][1];

	map<int, int> index;
	int m = n + 3;
	vector<vector<Edge> > edges(m);
	edges[2].push_back(Edge(1, n, 0));

	for(int i=0; i<n; ++i){
		edges[0].push_back(Edge(i+3, 1, 0));
		edges[i+3].push_back(Edge(2, 1, a[i][0] + a[i][1]));
		for(int j=0; j<2; ++j){
			int k;
			if(index[a[i][j]] == 0){
				k = index[a[i][j]] = m;
				++ m;
				edges.resize(m);
				edges[k].push_back(Edge(1, 1, 0));
			}else{
				k = index[a[i][j]];
			}
			edges[i+3].push_back(Edge(k, 1, a[i][j]));
		}
	}

	int ret = 0;
	for(int i=0; i<n; ++i)
		ret += a[i][0] + a[i][1];
	ret -= minCostFlow(edges, 0, 1, n);
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 0
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    ll sta,fin;
    int h1,m1,h2,m2,k;
    cin >>h1>>m1>>h2>>m2>>k;
    sta=h1*60+m1;
    fin=h2*60+m2;
    ll ans=fin-sta-k;
    if(k>0){
        cout<<ans<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
//#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define of(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof a)
#define uint unsigned int

const  int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

int n;
int a[N];
string s, t;
unordered_map<char, int> mp;
int minn[150];
set<int> v[150];

int main()
{
	ios::sync_with_stdio(false);
	cin >> s >> t;
	mem(minn, -1);
	for (int i = 0; s[i]; i++)
	{
		mp[s[i]] = 1;
		if (minn[s[i]] == -1)
		{
			minn[s[i]] = i;
			v[s[i]].insert(inf);
		}
		v[s[i]].insert(i);
	}
	for (auto i : t)
		if (!mp[i])
		{
			puts("-1");
			return 0;
		}
	int len = t.size();
	if (len == 1)
	{
		cout << minn[t[0]] + 1 << endl;
	}
	else
	{
		int mi = minn[t[0]];
		ll ans = 0;
		ll size = s.size();
		int flag = 0;
		for (int i = 1; t[i]; i++)
		{
			flag = 0;
			int tp = *(v[t[i]].upper_bound(mi));
			if (tp != inf)
			{
				flag = 1;
				mi = tp;
			}
			if (!flag)
			{
				ans += size;
				mi = minn[t[i]];
			}
		}
		ans += mi;
		cout << ans + 1 << endl;
	}
	return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   	ll n, count=0;
   	cin>>n;
   	ll arr[n];
   	for(ll i=0; i<n; i++){
   		cin>>arr[i];
   	}
   	for(ll j=0; j<n; j+=2){
   		if(arr[j]%2!=0){
   			count++;
   		}
   	}
   	cout<<count<<"\n";
    return 0;
}

Measured memory_bytes: 3644
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let a: i64 = itr.next().unwrap();
    let b: i64 = itr.next().unwrap();
    let x: i64 = itr.next().unwrap();

    let h = b / x;
    let l = if a > 0 { (a - 1) / x } else { -1 };

    println!("{}", h - l);
}


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<complex<ll>> V(N);
  for (pt& p : V) {
    int a, b;
    cin >> a >> b;
    p = {a, b};
  }
  sort(V.begin(), V.end(), [](pt a, pt b) {
    return atan2(a.real(), a.imag()) < atan2(b.real(), b.imag());
  });
  V.insert(V.end(), V.begin(), V.end());

  ll res = 0;
  for (int i = 0; i < N; i++) {
    pt p = {0, 0};
    for (int j = i; j < i + N; j++) {
      p += V[j];
      res = max(res, norm(p));
    }
  }
  cout << fixed << setprecision(15) << sqrt(res) << endl;

  return 0;
}


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

int Pow(int a, int n) {
  if (n == 0) return 1;
  if (n == 1) return a;
  if (n % 2 == 1) return (a * Pow(a, n-1));
  int t = Pow(a, n/2);
  return t*t;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int cnt_odd = 0, cnt_even = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] % 2 == 0) cnt_even++;
    else cnt_odd++;
  }
  int ans = Pow(3, N) - Pow(2, cnt_even);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;

signed main(){
  int n,k;
  cin>>n>>k;
  map<int,int> mp;
  REP(i,n){
    int a;
    cin>>a;
    mp[a]++;
  }
  if(mp.size()<=k){

    cout<<0<<endl;
  }else{
    vector<pair<int,int>> v;
    for(auto e:mp){
      v.emplace_back(MP(e.SEC,e.FIR));
    }
    sort(v.begin(),v.end(),greater<pair<int,int>>());
    int sum=0;
    REP(i,k){
      sum+=v[i].FIR;
    }
    cout<<n-sum<<endl;


  }
  return 0;
}


Measured memory_bytes: 18800
n, m = map(int,input().split())
light = [list(map(int,input().split())) for _ in range(m)]
check = list(map(int,input().split()))
ans = 0

for i in range(2 ** n):
    swicth = [0] * n
    
    for j in range(n):
        if ((i >> j) & 1):
            swicth[n - 1 -j] = 1
            
    check_cnt = 0        
    for k in range(m):
        a = light[k][0]
        swicth_on_cnt = 0
        for b in range(a):
            swicth_number = light[k][1+b]
            if swicth[swicth_number - 1] == 1:
                swicth_on_cnt += 1
        if swicth_on_cnt%2 == check[k]:
            check_cnt += 1

    if check_cnt == m:
        ans += 1

print(ans)
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long double PI =(acos(-1));

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > a(n,vector<int> (m));
    vector<int> b(m);
    vector<int> c(n);

    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin >> a.at(i).at(j);
        }
    }
    for(int i=0;i<m;++i){
        cin >> b.at(i);
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            c.at(i)+=a.at(i).at(j)*b.at(j);
        }
    }
    
    for(int i=0;i<n;++i){
        cout << c.at(i) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3160
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int K;
#define Maxn 105 
char S[Maxn];
int len1,len2,len;
ll ans=0;

int main(){
	scanf("%s",S+1);
	scanf("%d",&K);
	int flag=-1;
	len=strlen(S+1);
	for(register int i=2;i<=len;++i)
	    if(S[i]!=S[1]){
	    	flag=i;
	    	break;
		}	
	if(flag==-1){
		printf("%lld\n",1ll*len*K/2);
		return 0;
	}
	if(S[1]!=S[len]){
		int last=1;
		for(register int i=1;i<=len;++i)
		    if(i==len||S[i]!=S[i+1]){
		    	ans+=1ll*(i-last+1)/2*K;
		    	last=i+1;
			}
	}else{
		int last=flag;
		for(register int i=flag;i<=len;++i)
		    if(i==len||S[i]!=S[i+1]){
		    	if(i!=len)ans+=1ll*(i-last+1)/2*K;
				last=i+1;
			}
		int at=len;
		while(at>1&&S[at-1]==S[len])at--;
		ans+=1ll*(len-at+flag)/2*(K-1);
		ans+=1ll*(flag-1)/2;
		ans+=1ll*(len-at+1)/2;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
import sys
N = int(input())
A = sorted(list(map(int, sys.stdin.readline().split())))

d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

A = sorted(set(A))
t = [True] * (10 ** 6 + 1)
for a in A:
    if d[a] > 1:
        t[a] = False
    for i in range(a + a, 10 ** 6 + 1, a):
        t[i] = False
print(sum(1 for a in A if t[a]))


Measured memory_bytes: 44432
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

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

    if (a > b) cout << 0 << endl;
    else if (n == 1 && a != b) cout << 0 << endl;
    else if (n <= 2) cout << 1 << endl;
    else cout << b * (n - 2) - a * (n - 2) + 1 << endl;

    return 0;
}


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

const int MAX_N = 2e3 + 6, inf = 1e9 + 7, MOD = 1e9 + 7;
int n, m, ans;
string table[MAX_N];
int up[MAX_N][MAX_N];
int down[MAX_N][MAX_N];
int righ[MAX_N][MAX_N];
int lef[MAX_N][MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> table[i];
		table[i] = '#' + table[i];
	}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			up[i][j] = (table[i][j] == '#'? 0: 1 + up[i - 1][j]);

	for (int i = n; i; i--)
		for (int j = 1; j <= m; j++)
			down[i][j] = (table[i][j] == '#'? 0: 1 + down[i + 1][j]);

	for (int i = 1; i <= n; i++)
		for (int j = m; j; j--)
			righ[i][j] = (table[i][j] == '#'? 0: 1 + righ[i][j + 1]);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			lef[i][j] = (table[i][j] == '#'? 0: 1 + lef[i][j - 1]);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			ans = max(ans, lef[i][j] + righ[i][j] + up[i][j] + down[i][j] - 3);

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 67072
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
P=get_i
ans=0
(N-2).times do|i|
  if [P[i],P[i+1],P[i+2]].sort[1]==P[i+1]
    ans+=1
  end
end
puts ans

Measured memory_bytes: 1788
using namespace std;
#include<bits/stdc++.h> 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
 
int main(){
  int n;
  cin >> n;
  vector<vector<int>> F(n,vector<int>(10,0));
  // vector<vector<vector<int>>> F(n,vector<vector<int>>(5,vector<int>(2,0)));
  rep(i,n)rep(j,10)cin>>F.at(i).at(j);
  vector<vector<int>> P(n,vector<int>(11));
  rep(i,n)rep(j,11)cin>>P.at(i).at(j);
 
  ll ans = 0;//最大値を求める。
  //joshinoお姉ちゃんの見せの時間
  for(int bit = 1; bit < (1<<10); bit++){
    vector<int> num(100,0);
    for(int i = 0; i < 10; i++){//10の時間
      if(bit&(1<<i)){//joshino open
        for(int j = 0; j < n; j++){
          if(F.at(j).at(i))num.at(j)++;
        }
      }
    }
    ll tmp = 0;
    rep(i,n){
      tmp+=P.at(i).at(num.at(i));
    }
    if(bit==1)ans = tmp;
    else ans = max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
	int N;
//	int array[101]={};
	int input;
	int color[9]={};
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> input;
		color[min((input/400),8)]++;
	}
	
	int Min=0,Max=0;
	for(int i=0;i<8;i++){
		if(color[i]>0){
			Min++;
			Max++;
		}
	}
	Max = Max+color[8];
	if(Min==0){
		Min=1;
	}
	cout << Min << " " << Max;
	
	return 0;
}

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


int main(){
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.size()/2; i++)
  if (S.at(i) != S.at(S.size()-1-i)){
    ans++;
  }
 cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;

bool cmp(const pair<lli, lli> left, const pair<lli, lli> right) {
	return left.second < right.second;
}

using namespace std;

int main() {
	lli n, m, p, q;
	vector<lli> vec;

	cin >> n >> m;
	cout << (n%(m*2+1)==0? n / (m * 2 + 1): n / (m * 2 + 1) +1);

}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n, k;
    cin >> n >> k;
    vector<ll>a(n);
    vector<ll>ruiseki(n);
    rep(i,n){
        cin >> a[i];
        if(i==0)ruiseki[i] = max(0LL, a[i]);
        else ruiseki[i] = ruiseki[i-1] + max(0LL, a[i]);
    }
    ll ans = -1000000000000000;
    //show(ans);
    vector<ll>b(n-k+1,0LL);
    rep(i,k){
        b[0]+=a[i];
    }
    rep(i,n-k){
        b[i+1] = b[i] - a[i] + a[i+k];
    }
    if(0)rep(i,n-k+1){
        show(b[i]);
    }
    if(0)rep(i,n){
        show(ruiseki[i]);
    }
    rep(i,n-k+1){
        if(i==0){
            //i~i+k-1までを黒
            ans = max(ans, b[i] + ruiseki[n-1]-ruiseki[i+k-1]);
            //白
            ans = max(ans, ruiseki[n-1]-ruiseki[i+k-1]);
            
        }
        else{
            //i~i+k-1までを黒
            ans = max(ans, b[i] + ruiseki[i-1]+ruiseki[n-1]-ruiseki[i+k-1]);
            //白
            ans = max(ans, ruiseki[i-1]+ruiseki[n-1]-ruiseki[i+k-1]);
        }
        //show(ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    def k_fix_way(com_n, com_r):
        if (com_n, com_r) in kmemo:
            return kmemo[(com_n, com_r)]
        res = kmemo[(com_n, com_r)] = fac[com_n] * inv[com_n - com_r] * fac[com_n] * inv[com_r] * inv[
            com_n - com_r] % md
        return res

    kmemo = {}

    def centroid(u=0, pu=-1):
        res = []
        is_centroid = True
        u_nodes = 1
        for cu in to[u]:
            if cu == pu: continue
            res += centroid(cu, u)
            cu_nodes = n_nodes[cu]
            if cu_nodes > n / 2: is_centroid = False
            u_nodes += cu_nodes
        n_nodes[u] = u_nodes
        if n - u_nodes > n / 2: is_centroid = False
        if is_centroid: res.append(u)
        return res

    md = 10 ** 9 + 7
    to = defaultdict(list)
    n = int(input())
    for _ in range(n - 1):
        u, v = map(int, input().split())
        u, v = u - 1, v - 1
        to[u].append(v)
        to[v].append(u)
    # 部分木の頂点数を記録しながら重心を求める
    n_nodes = [0] * n
    cc = centroid()
    # print(cc)
    # 階乗の準備
    n_max = n
    fac = [1]
    inv = [1] * (n_max + 1)
    k_fac_inv = 1
    for i in range(1, n_max + 1):
        k_fac_inv = k_fac_inv * i % md
        fac.append(k_fac_inv)
    k_fac_inv = pow(k_fac_inv, md - 2, md)
    for i in range(n_max, 1, -1):
        inv[i] = k_fac_inv
        k_fac_inv = k_fac_inv * i % md
    # 重心が2つの（グラフを二等分できる）場合
    if len(cc) == 2:
        print(pow(fac[n // 2], 2, md))
        exit()
    # 重心が1つの場合
    # サブツリーの頂点数のリストsubtree_node_n作成
    subtree_node_n = []
    c = cc[0]
    for u in to[c]:
        u_nodes = n_nodes[u]
        if u_nodes > n / 2: continue
        subtree_node_n.append(u_nodes)
    if c != 0: subtree_node_n.append(n - n_nodes[c])
    # print(subtree_node_n)

    # dp[i][j]をi番目のサブツリーまでみて、j個の頂点を固定したときの決め方として求める
    dp = [0] * n
    dp[0] = 1
    for i, node_n in enumerate(subtree_node_n):
        for j in range(n - 1, -1, -1):
            pre = dp[j]
            if pre == 0: continue
            for k in range(node_n, 0, -1):
                dp[j + k] = (dp[j + k] + pre * k_fix_way(node_n, k)) % md
    # print(dp)
    # 包除原理
    ans = 0
    coff = 1
    for j in range(n):
        ans = (ans + coff * dp[j] * fac[n - j]) % md
        coff *= -1
    print(ans)

main()


Measured memory_bytes: 121176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        Double[] heads = new Double[n];

        for (int i = 0; i < n; i++) {
            heads[i] = Double.parseDouble(st.nextToken());
        }
        moreHeadsProbability(heads);
    }

    public static void moreHeadsProbability(Double[] heads) {
        int n = heads.length;

        //if there is only 1 or 2 coins, the probability of more heads than tails
        // is the probability of flipping all heads
        if (n == 1) {
            System.out.println(heads[0]);
            return;
        }

        if (n == 2) {
            System.out.println(heads[0]*heads[1]);
            return;
        }

        //initialize 2 x (n-1)/2 +1 table for bottom up
        Double[][] soln = new Double[2][((n - 1)/ 2) + 1];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < ((n - 1) / 2) + 1; j++) {
                soln[i][j] = 0D;
            }
        }

        //base case
        soln[0][0] = heads[0];
        soln[0][1] = 1 - heads[0];

        //note we only need the results from n-1 coins, so we don't need to store results for all n coins
        for (int i = 1; i < n; i++) {
            soln[1][0] = soln[0][0] * heads[i];
            for (int j = 1; j <= Math.min(i + 1, (n - 1) / 2); j++) {
                soln[1][j] = soln[0][j] * heads[i] + soln[0][j - 1] * (1 - heads[i]);
            }
            soln[0] = soln[1].clone();
        }
        //add probability of 0 tail to (n-1)/2 tails for n coins
        double sum = 0;
        for (int i = 0; i <= (n - 1) / 2; i++) {
            sum += soln[1][i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 61264
#include <bits/stdc++.h>
 
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
/* DSU 
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    rank[v] = 0;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}
*/ 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
 
ll mod(ll a, ll b) {return (a % b + b) % b;}
 
ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
 
ll isPrime(ll number)
{
    if(number < 2) return 0;
    if(number == 2) return 1;
    if(number % 2 == 0) return 0;
    for(int i=3; (i*i)<=number; i+=2)
{
        if(number % i == 0 ) return 0;
    }
    return 1;

}
 
using namespace std;

int main()
{
	fast;
	ll X; cin>>X;
	vector<ll>ex(X+1,0);
	ex[1] = 1;
	for(ll i = 2; i <= X; i++)
	{
		ll v = i*i;
		while(v <= X)
		{
			ex[v] = 1;
			v = v * i;
		}
	}
	for(ll i = X; i >= 1; i--)
	{
		if(ex[i] == 1)
		{
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3604
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    count = 0
    for i in range(n):
        if a[i] % arg != 0:
            count += a[i] // arg
        else:
            count += a[i] // arg - 1
    return count <= k

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n, k = MAP()
a = LIST()
if k == 0:
    print(max(a))
else:
    print(meguru_bisect(0, max(a)+1))

Measured memory_bytes: 32588
<?php

fscanf(STDIN, "%d", $N);
$input = explode(" ", trim(fgets(STDIN)));

sort($input);

$arg=[];
$min=0;
for ($i=1; $i < $N; $i++) { 
	$arg[$i] = $input[$i] - $input[$i-1];
}

sort($arg);

foreach ($arg as $key => $value) {
	if ($value>0) {
		$min = $value;
		break;
	}
}

function sol($input,$min){
	$newmin=$min;
	foreach ($input as $key => $value) {
		$nowmin = $value % $min;
		if ($nowmin < $min && $nowmin != 0) {
			$newmin = $nowmin;
		}
	}
	if ($newmin != $min) {
		return sol($input,$newmin);
	}else{
		return $min;
	}
}

if ($min==0) {
	echo $input[0];
}else{
	$min = sol($input,$min);
	echo $input[0]>$min?$min:$input[0];
}


Measured memory_bytes: 18932
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}

void solve()
{
    int n;
    cin >> n;
    if (n & 1)
        printf("%.12lf\n", (((n / 2) + 1.0))/n);
    else
        puts("0.500000000");
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

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

using namespace std;

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

	int n;
	cin >> n;
	int cnt = 0;
	for(int i =1; i<=n; ++i) {
		int x; cin >> x;
		if (i % 2 && x % 2) cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 3648
def main():
  [n, k] = [int(i) for i in input().split()]
  [r, s, p] = [int(i) for i in input().split()]
  T =  input()
  
  my = T.replace("r", "hoge").replace("s", "r").replace("p", "s").replace("hoge", "p") 
  for i in range(k, n):
    if my[i] == my[i-k]:
      my = my[:i] + "l" + my[i+1:]  

  print(my.count("r")* r + my.count("s")*s + my.count("p")* p)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 3748
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline
import collections


def main():
    S = input().strip()


    N = len(S)
    P = 2019
    M = [0] * N
    for i, s in enumerate(S[::-1]):
        M[i] = (int(s) * pow(10, i, P)) % P

    MA = []
    MA.append(M[0])
    c = collections.Counter()
    ans = 0
    c[0] += 1
    ans += c[MA[0]]
    c[M[0]] += 1
    for i in range(1, N):
        MA.append((MA[i - 1] + M[i]) % P)
        ans += c[MA[i]]
        c[MA[i]] += 1

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
using ull = long long;

ull calc(ull w, ull h)
{
	ull ans = LLONG_MAX;
	for (ull i = 1; i < h; i++) {
		ull b1 = i * w;
		if (w % 2 == 0) {
			ull b2 = (w / 2) * (h - i);
			ans = min(ans, abs(b1 - b2));
		} else {
			ull b2 = (w / 2) * (h - i);
			ull b3 = (w / 2 + 1) * (h - i);
			ull tmp = max(abs(b1 - b2), abs(b1 - b3));
			tmp = max(tmp, abs(b2 - b3));
			ans = min(ans, tmp);
		}
	}
	return ans;
}

int main()
{
	ull h, w;
	cin >> h >> w;
	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ull ans = LLONG_MAX;
	ans = min(w, h);
	ans = min(ans, calc(w, h));
	ans = min(ans, calc(h, w));
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}
use input::*;

fn main() {
    let (n, k, x, y): (usize, usize, usize, usize);
    input!(n);
    input!(k);
    input!(x);
    input!(y);

    if k < n {
        p(x * k + y * (n - k));
    } else {
        p(x * n);
    }
}

Measured memory_bytes: 4352
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    char a;
    cin >> a;
    vector<ll> b(5);
    b = {'a', 'e', 'o', 'u', 'i'};
    rep(0, i, 5)
    {
        if (b.at(i) == a)
        {
            cout << "vowel" << endl;
            return 0;
        }
    }

    cout << "consonant" << endl;
}

Measured memory_bytes: 3604
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long int lli;
#define rept(x, s, n) for (int x = s; x < n; x++)

int main(void) {
	int   N,i;
	char  A[101];
	
	
	s_cin(A);
	N = strlen(A);
	
	rept(i, 1, N+1) {
		if ((i % 2 && (A[i - 1] == 'L'))||
			(!(i%2) &&(A[i - 1] == 'R'))){
			s_cout("No"); return 0;
		}	
	}
	
	s_cout("Yes");
	return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

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

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

int main(void){
  int N, K, X, Y;
  cin >> N;
  cin >> K;
  cin >> X;
  cin >> Y;

  cout << min(K, N)*X+max(N-K, 0)*Y << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)
 
  dp = [[-INF] * (N+1) for _ in range(N+1)]
  dp[0][0] = 0
 
  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)
 
main()

Measured memory_bytes: 136000
#include <iostream>
#include <map>

using namespace std;

bool ans[3][3];

int main() {
    int num, N;
    map<int, pair<int, int> > m;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> num;
            m.insert(make_pair(num, make_pair(i, j)));
        }
    }
    int b;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> b;
        if (m.count(b)) {
            ans[m[b].first][m[b].second] = 1;
        }
    }
    for (int i = 0; i < 3; i++) {
        int sum = ans[i][0] + ans[i][1] + ans[i][2];
        if (sum == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 3; i++) {
        int sum = ans[0][i] + ans[1][i] + ans[2][i];
        if (sum == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    int sum = ans[0][0] + ans[1][1] + ans[2][2];
    if (sum == 3) {
        cout << "Yes" << endl;
        return 0;
    }
    sum = ans[0][2] + ans[1][1] + ans[2][0];
    if (sum == 3) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << 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);
		int n = sc.nextInt();
		int[] data = new int[n-1];
		int[] data2 = new int[n];
		for(int i=0;i<n-1;i++)
			data[i] = sc.nextInt();
		for(int i=0;i<n-1;i++)
			data2[data[i]-1]++;
		for(int i=0;i<n;i++)
			System.out.println(data2[i]);
	}
}



Measured memory_bytes: 61776
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int a=read(),b=read(),c=read(),d=read();
 
int main(){
if (abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d) puts("Yes");
else puts("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<utility>
#include<bitset>
#include<climits>
#include<cstdio>
#include<cassert>
using namespace std;


vector<pair<int,int> > edge;
enum hogehoge{
  A=0,B=1,W=2,X=3,Y=4,Z=5
};
void make_map(){
  pair<int,int> tmp;
  tmp.first=X;//a
  tmp.second=Y;
  edge.push_back(tmp);
  tmp.first=Y;//b
  tmp.second=X;
  edge.push_back(tmp);
  tmp.first=B;//w
  tmp.second=Y;
  edge.push_back(tmp);
  tmp.first=-1;//x
  tmp.second=Z;
  edge.push_back(tmp);
  tmp.first=X;//y
  tmp.second=-1;
  edge.push_back(tmp);
  tmp.first=W;//z
  tmp.second=B;
  edge.push_back(tmp);
}



string p;
void init(){
  p="";
  edge.clear();
}

bool input(){
  cin>>p;
  if(p=="#"){
    return false;
  }else{
    return true;
  }
}

int go(int now,char in){
  if(in=='1'){
    return edge[now].second;
  }else if(in=='0'){
    return edge[now].first;
  }else{
    return -1;
  }
}


string solve(){
  int pos=A;
  for(int i=0;i<p.size();i++){
    pos=go(pos,p[i]);
    if(pos==-1)return "No";
  }
  if(pos==B){
    return "Yes";
  }else{
    return "No";
  }
}

int main(){
  make_map();
  while(init(),input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1192
//       |----|       /\      |    |   -----   |
//       |   /       /  \     |    |     |     |
//       |--/       /----\    |----|     |     |
//       |   \     /      \   |    |     |     |
//       |    \   /        \  |    |   -----   -------

//https://www.geeksforgeeks.org/longest-sub-array-sum-k/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define double long double
int need[3];
int arr[8];
int n;
int32_t main()
{
    IOS;
    cin>>n>>need[0]>>need[1]>>need[2];
    for(int i=0;i<n;i++)
    	cin>>arr[i];
    int mini=1e18;
    for(int i=0;i<(int)pow(4,n);i++)
    {
    	int sum1=0,sum2=0,sum3=0,join1=0,join2=0,join3=0;
    	int temp=i;
    	for(int j=0;j<n;j++)
    	{
    		if(temp%4==0)
    		{
    			sum1+=arr[j];
    			join1++;
    		}
    		if(temp%4==1)
    		{
    			sum2+=arr[j];
    			join2++;
    		}
    		if(temp%4==2)
    		{
    			sum3+=arr[j];
    			join3++;
    		}
    		temp/=4;
    	}
    	if(join1==0||join2==0||join3==0)
    		continue;
    	int ans=(join1+join2+join3-3)*10+abs(sum1-need[0])+abs(sum2-need[1])+abs(sum3-need[2]);
    	mini=min(mini,ans);
    }
    cout<<mini;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){
  int N;
  cin>>N;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  vector<int> aa(N);
  vector<int> bb(N);
  vector<int> cc(N);

  for(int i=0;i<N;i++){
    cin>>a[i];
    cin>>b[i];
    cin>>c[i];
    aa[i]=0;
    bb[i]=0;
    cc[i]=0;
  }
  aa[0]=a[0];
  bb[0]=b[0];
  cc[0]=c[0];

for(int i=1;i<N;i++){
  aa[i] = max(bb[i-1],cc[i-1]) + a[i];
  bb[i] = max(aa[i-1],cc[i-1]) + b[i];
  cc[i] = max(bb[i-1],aa[i-1]) + c[i];
  //cout << aa[i] << "," << bb[i] << "," << cc[i] << endl;
}
//cout << aa[N-1] << "," << bb[N-1] << cc[N-1] << endl;
cout << max({aa[N-1],bb[N-1],cc[N-1]}) << endl;

  return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL dp[2005][2005] = {};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int s;
    cin >> s;
    if(s <= 2) {
        cout << 0 << endl;
        return 0;
    }

    LL sum[2005] = {};
    LL tmp[2005] = {};
    LL res = 1;
    for(int i = 1; i <= s / 3; ++i) {
        for(int j = s; j >= 3; --j) {
            if(i == 1) {
                dp[i][s] = 1;
                dp[i][j] = 1;
                sum[j + 3] += 1;
            } else {
                dp[i][j] = sum[j] % MOD;
                if(j == s) {
                    res += dp[i][s];
                    res %= MOD;
                }
                sum[j] = 0;
                sum[j + 3] += dp[i][j];
            }
        }
        for(int j = 4; j <= s; ++j) {
            sum[j] += sum[j - 1];
            sum[j] %= MOD;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 13992