akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair <ll,int> P;

int n,q,k;
ll dist [100005];
vector<P> g[100005];
const ll INF = 1e14;
int main() {
  cin >> n;

  for(int i = 0; i < n - 1; i++) {
    int a,b; ll c;
    cin >> a >> b >> c;
    a--,b--;
    g[a].push_back(P(c,b));
    g[b].push_back(P(c,a));
  }

  cin >> q >> k;
  k--;
  priority_queue<P,vector<P>,greater<P> > Q;

  Q.push(P(0,k));
  fill(dist,dist+n+1,INF);
  dist[k] = 0;

  while(!Q.empty()) {
    P p = Q.top();
    Q.pop();
  
    if(p.first > dist[p.second]) continue;
    
    for(int i = 0; i < g[p.second].size(); i++) {
      P v = g[p.second][i];
    
      if(dist[v.second] > dist[p.second] + v.first) {
	dist[v.second] = dist[p.second] + v.first;
	Q.push(P(dist[v.second],v.second));
      }
    }
  }



  for(int i = 0; i < q; i++) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    ll ans = dist[x] + dist[y];
    cout << ans << endl;
  }
}
  
  


Measured memory_bytes: 11120
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  vector<int> A(3);
  int d;
  cin >> A[0] >> A[1] >> A[2] >> d;
  if (abs(A[0]-A[2]) <= d) cout << "Yes" << endl;
  else if (abs(A[0]-A[1]) <= d and abs(A[1]-A[2]) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF)
	{
		int s;
		s=a*b-b-(a-1);
		printf("%d\n",s);
	}
	return 0;
}


Measured memory_bytes: 256
//#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f_(i,a,b) for (int i=a;i>=b;i--)
#define f(i,a,b) for (int i=a;i<=b;i++)
 
int n,L,q,x[100005],cha[100005][30];
int main() {
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	scanf("%d", &n);
	f(i,1,n) scanf("%d", &x[i]);
	scanf("%d", &L);
	int it=n;
	f_(i,n,1) {
		while (x[it]-x[i]>L) it--;
		cha[i][0]=it;
	}
	for (int j=1;j<=20;j++) f(i,1,n) cha[i][j]=cha[cha[i][j-1]][j-1];
//	f(i,1,n) cout<<cha[i]<<" ";
//	cout<<"\n";
//	f(i,1,n) cout<<cha2[i]<<" ";
//	cout<<"\n";
	scanf("%d", &q);
	while (q--) {
		int a,b;
		scanf("%d %d", &a, &b);
		if (a>b) {
			a=a+b;
			b=a-b;
			a=a-b;
		}
		int dem=0,pos=a;
		for (int i=20;i>=0;i--) {
			if (cha[pos][i]<b) {
				pos=cha[pos][i];
				dem+=(1<<i);
			}
		}
		printf("%d\n", dem+1);
	}
	return 0;
}

Measured memory_bytes: 12928
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int H, W, K;
char s[300][300];

vector<int> v;
bool st[300];
int ans[300][300];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W >> K;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
            if(s[i][j] == '#') st[i] = true;
        }
        if(st[i]) v.push_back(i);
    }
    int cnt = 0;
    for(int i = 0; i < H; i++){
        if(!st[i]) continue;
        int tmp = 0;
        cnt++;
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#') {
                tmp++;
                if(tmp >= 2) cnt++;
            }
            ans[i][j] = cnt;
        }
    }
    for(int i = v[0]-1; i >= 0; i--){
        for(int j = 0; j < W; j++){
            ans[i][j] = ans[v[0]][j];
        }
    }
    for(int i = 0; i < v.size(); i++){
        int m;
        if(i+1 == v.size()) m = H;
        else m = v[i+1];
        for(int j = v[i]+1; j < m; j++){
            for(int k = 0; k < W; k++){
                ans[j][k] = ans[v[i]][k];
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << ans[i][j];
            if(j == W-1) cout << endl;
            else cout << ' ';
        }
    }
}

Measured memory_bytes: 1280
n,m,l=gets.split.map(&:to_i)
a=(1..n).map{gets.split.map(&:to_i)}
b=(1..m).map{gets.split.map(&:to_i)}
c=[]
for i in 0...n
    c<<[]
    for j in 0...l
        s=0
        for k in 0...m
            s+=a[i][k]*b[k][j]
        end
        c[i]<<s
    end
end
c.each do |s|
    puts s.join(" ")
end


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


void solve(long long N, long long T, std::vector<long long> t){
    ll ans = 0;
    for(ll i=0; i< N-1; i++){
        ans += min(T, t[i+1]-t[i]);
    }
    ans += T;
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long T;
    scanf("%lld",&T);
    std::vector<long long> t(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&t[i]);
    }
    solve(N, T, std::move(t));
    return 0;
}


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

int main() {
	int n, m;
	string s;
	while (cin >> n, n) {
		cin >> m;
		cin >> s;
		map<int, int> ioi;

		int level = 0;
		for (int i = 0; i < m; i++) {
			if (s[i] == 'I') {
				while (s[i+1] == 'O' && s[i+2] == 'I') {
					level++;
					i+=2;
				}
				ioi[level]++;
				level = 0;
			}
		}
		ioi[0] = 0;

		long long cnt = 0;
		for (map<int, int>::iterator it = ioi.begin(); it != ioi.end(); it++) {
			if (it->first - n + 1 < 0) continue;
//			cout << it->first << ' ' << it->second << endl;
			cnt += (it->first - n + 1) * it->second;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1960
#main
arr = Array.new
until (n = gets) == "0\n"
  a = Array.new
  (n.to_i).times do
    a << gets.to_i
  end
  arr << a
end
arr.each do |i|
  mss = 0
  sum = 0
  max = -100000
  0.upto(i.length - 1) do |j|
    if i[j] > max
      max = i[j]
    end
    sum += i[j]
    sum = 0 if sum < 0
    mss = sum if mss < sum
  end
  puts (max < 0) ? max : mss
end

Measured memory_bytes: 6108
# abc149_d.py
def janken(idx,mine):
    if i >= K:
        if flg[i-K] and T[i-K]==T[i]:
            return 0
    flg[i] = True
    if mine=="r":
        return R
    if mine=="p":
        return P
    if mine=="s":
        return S

N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
flg = [False]*N
ans = 0
for i,v in enumerate(T):
    if v=="s":
        ans += janken(i,"r")
    elif v=="r":
        ans += janken(i,"p")
    elif v=="p":
        ans += janken(i,"s")
print(ans)

Measured memory_bytes: 9848
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
    while(1) {
        int n, x;
        cin >> n >> x;
        
        if(n == 0 && x == 0) break;
    
        int res = 0;
        // a1 > a2 > a3
        for(int a1=3; a1<=n; a1++) {
            for(int a2=2; a2<a1; a2++) {
                for(int a3=1; a3<a2; a3++) {
                    if(a1+a2+a3 == x) res++;
                }
            }
        }
    
        cout << res << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int x=0;
    cin>>s>>t;
    if(s[0]==t[0])
    {
        x++;
    }
    if(s[1]==t[1])
    {
        x++;
    }
    if(s[2]==t[2])
    {
        x++;
    }
    cout<<x;


  return 0;
}


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

const double PI = acos(-1.0);

int main() {
    int n;
    double l, a;
    
    while(cin >> n && n != -1) {
        l = 1.0; a = 0;
        for(int i=0; i<n-1; i++) {
            a += atan(1/l);
            l = sqrt(l*l+1);
        }
        cout << l * cos(a) << endl << l * sin(a) << endl;
    }
}


Measured memory_bytes: 3436
#include <iostream>

using namespace std;

int main()
{
	string s; cin>>s;
	int n; cin>>n;
	int res=0;
	while(n--){
		string t; cin>>t;
		if((t+t).find(s)!=string::npos)
			res++;
	}
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
int h[1001];
signed main() {
	int n, t, a; cin >> n >> t >> a;
	rep(i, n)cin >> h[i];
	double gs = 1145141919; int nm = 0;
	rep(i, n) {
		double nt = t - h[i] * 0.006;
		nt = abs(nt - (double)a);
		if (gs > nt) {
			gs = nt;
			nm = i;
		}
	}
	cout << nm + 1 << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
aa = [input() for _ in range(n)]
bb = [input() for _ in range(m)]

match = False
for y in range(n-m+1):
    for x in range(n-m+1):
        target = ([''.join(aa[i][x:x+m]) for i in range(y, y+m)])
        if match or target == bb:
            match = True

print('Yes' if match else 'No')

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

using namespace std;

int main(void) {
  string s;
  cin >> s;

  int Aindex, Zindex;
  for(int i = 0; i < s.length(); i++) {
    if(s[i] == 'A') {
      Aindex = i;
      break;
    }
  }

  for(int i = s.length() - 1; i >= 0; i--) {
    if(s[i] == 'Z') {
      Zindex = i;
      break;
    }
  }

  cout << Zindex - Aindex + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;

int main() {
    int H, W, K; cin >> H >> W >> K;
    vvi c(W, vi(H));
    int ans = 0;

    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char tmp; cin >> tmp;
            if (tmp == '.') c.at(j).at(i) =0;
            else c.at(j).at(i) =1;
        }
    }
    
    for (int bit = 0; bit < (1 << W); bit++) {
        vi tmp(H, 0);
        for (int i = 0; i < W; i++) {
            if (bit & (1 << i)) {
                for (int j = 0; j < H; j++){
                    tmp.at(j) += c.at(i).at(j);
                }   
            }
        }

        for (int bit2 = 0; bit2 < (1 << H); bit2++) {
            int tmp2 = 0;
            for (int j = 0; j < H; j++) {
                if (bit2 & (1<<j)) {
                    tmp2 += tmp.at(j);
                }
            }
            if (tmp2 == K)  ans++;
            
        }
    }
    cout << ans;
}

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

int main() {
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif // ONLINE_JUDGE
	string s1, s2;
	cin >> s1;
	cin >> s2;
	for (int i=0; i<s1.size(); i++) {
		if (s1[i] != s2[i]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
using namespace std;
double x,y,dir=M_PI/2.0;
int a,b;
char c;
int main(){
  x=y=0.0;
  while(cin>>a>>c>>b&&a){
    x-=cos(dir)*(double)a;
    y+=sin(dir)*(double)a;
    dir+=b/180.0*M_PI;
    while(dir>=2.0*M_PI)dir-=2.0*M_PI;
    while(dir<0.0)dir+=2.0*M_PI;
     
  }
  cout<<(int)x<<endl<<(int)y<<endl;
  return 0;
}


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

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

    if (a == 'H')
    {
        cout << b << endl;
    }
    else
    {
        if (b == 'H')
        {
            cout << 'D' << endl;
        }
        else
        {
            cout << 'H' << endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	double b,sum=0; 
	for(int i=1;i<=a;i=i+2)
	sum++;
	b=sum/a;
	cout<<fixed<<setprecision(10)<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main() {
	int n, m,sum = 0,t[1005],cnt = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		sum += t[i];
	}
	for (int i = 0; i < n; i++)if (sum * 1.0 / (4 * m) <= t[i])cnt++;
	if (cnt >= m)cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[4];
int main(){
	int n;
	while(cin>>n){
		int k=0;
		while(n){
			a[k++]=n%10;
			n/=10;
		}
		if(a[0]==a[1]&a[0]==a[2]||a[1]==a[2]&&a[1]==a[3]){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n; cin>>n;
    long long sum = 0;
    for(long long i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    cout << sum;
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mp make_pair
#define mm(a) memset(a,-1,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define endl "\n"
#define ld long double
#define mod 1000000007
#define BRAHAMASTRA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    BRAHAMASTRA
    ll t; t=1;
    // cin >>t;
    while(t--)
    {
        ll n; cin >>n;
        string s; cin >>s;
        ll cnt = 0;
        ll l = 0,r=n-1;
        while(l<r)
        {
            if(s[l]=='W' && s[r]=='R')swap(s[l],s[r]),l++,r--,cnt++;
            if(s[l]=='W' and s[r]=='W')r--;
            if(s[l]=='R' and s[r]=='R')l++;
            if(s[l]=='R' and s[r]=='W')l++,r--;
        }
        // cout<<s<<endl;
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    int n;
    int sum = 0;

    cin >> n;

    int tmp = n;
    while (tmp != 0) {
        sum += tmp % 10;
        tmp /= 10;
    }

    if (n % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

if all(a>=0 for a in A):
    A.sort()
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()
if all(a<0 for a in A):
    A.sort(reverse=K%2==0)
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()
if N==K:
    ans = 1
    for a in A:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

arr = []
for a in A:
    if a < 0:
        arr.append((-a,1))
    else:
        arr.append((a,0))

arr.sort()
pz = []
ng = []
for _ in range(K):
    v,s = arr.pop()
    if s:
        ng.append(v)
    else:
        pz.append(v)

if len(ng)%2 == 0:
    ans = 1
    for v in ng:
        ans *= v
        ans %= MOD
    for v in pz:
        ans *= v
        ans %= MOD
    print(ans)
    exit()

b = pz[-1] if pz else None
c = ng[-1] if ng else None
a = d = None
while arr and (a is None or d is None):
    v,s = arr.pop()
    if s:
        if a is None:
            a = v
    else:
        if d is None:
            d = v

if (a is None or b is None) and (c is None or d is None):
    assert False

ans = 1
if a is None or b is None:
    ans = d
    for v in ng[:-1]:
        ans *= v
        ans %= MOD
    for v in pz:
        ans *= v
        ans %= MOD
elif c is None or d is None:
    ans = a
    for v in ng:
        ans *= v
        ans %= MOD
    for v in pz[:-1]:
        ans *= v
        ans %= MOD
else:
    if a*c > b*d:
        ans = a
        for v in ng:
            ans *= v
            ans %= MOD
        for v in pz[:-1]:
            ans *= v
            ans %= MOD
    else:
        ans = d
        for v in ng[:-1]:
            ans *= v
            ans %= MOD
        for v in pz:
            ans *= v
            ans %= MOD
ans %= MOD
print(ans)

Measured memory_bytes: 39676
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(),m = sc.nextInt(),x=sc.nextInt();
    int rikai[]=new int[m];
    int money[]=new int[n];
    int book[][]=new int[n][m];
    long min =-1;
    for(int i=0;i<n;i++){
      money[i]=sc.nextInt();
      for(int j=0;j<m;j++){
        book[i][j]=sc.nextInt();
      }
    }
    min = search(0,n,m,x,0,rikai,money,book,-1);
    pl(min+"");
  }

  public static long search(int now,int n,int m,int x,long nowm,int[]rikai,int money[],int[][]book,long min){
    boolean flg=true;
    nowm+=money[now];
    for(int i=0;i<m;i++){
      rikai[i]+=book[now][i];
      if(rikai[i]<x){
        flg=false;
      }
    }
    if(flg){
      if(min==-1||min>nowm){
        min = nowm;
      }
    }else{
      for(int i=now+1;i<n;i++){
        min = search(i,n,m,x,nowm,rikai,money,book,min);
      }
    }
    for(int i=0;i<m;i++){
      rikai[i]-=book[now][i];
    }
    nowm-=money[now];
    if(now!=n-1){
      min = search(now+1,n,m,x,nowm,rikai,money,book,min);
    }
    return min;
  }

  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n+1);
    int ans = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a > n) ans++;
        else v[a]++;
    }
    for(int i=1; i<=n; i++){
        if(v[i] >= i) ans += v[i] - i;
        else ans += v[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
class Program
{
	static void Main()
	{
        string[] input = Console.ReadLine().Split(' ');
        string[] kyori = Console.ReadLine().Split(' ');
        int k = int.Parse(input[0]);
        int n = int.Parse(input[1]);
        int nagaikyori = 0;
        for (int i = 0; i < kyori.Length; i++) {
            if (i == kyori.Length - 1){
                if (k + int.Parse(kyori[0]) - int.Parse(kyori[i]) > nagaikyori){
                    nagaikyori = k + int.Parse(kyori[0]) - int.Parse(kyori[i]);
                }
            } else {
                if (int.Parse(kyori[i+1]) - int.Parse(kyori[i]) > nagaikyori){
                    nagaikyori = int.Parse(kyori[i+1]) - int.Parse(kyori[i]);
                }
            }
        }
        Console.WriteLine(k - nagaikyori);
	}

    static string equalCheck(string target1,string target2){
        if (target1 == target2){
            return "Yes";
        } else {
            return "No";
        }
    }
}

Measured memory_bytes: 30428
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	long long int N;
	cin >> N;
	
	long long int result = N;
	for (long long int i = 1; i <= ceil(sqrt(N)); ++i) {		
		if (N % i == 0) {
			result = max(N / i,i);
		}
		
		if (i == result) {
			break;
		}
	}
	
	cout << (result > 0 ? (int) log10 ((double) result) + 1 : 1);
	return 0; 
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;

int main() {
	ll n, m;
	cin >> n >> m;
	ll dp[114514], a;
	for (ll i = 0; i < m; i++) {
		cin >> a;
		dp[a] = -1;
	}
	dp[0] = 1;
	if (dp[1] == -1)dp[1] = 0;
	else dp[1] = 1;
	for (int i = 2; i < n+1; i++) {
		if (dp[i] == -1)dp[i] = 0;
		else dp[i] = (dp[i - 1] + dp[i - 2])%mod;
	}
	cout << dp[n] << endl;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int left = A + B;
    int right = C + D;

    if(left > right)
    {
        cout << "Left" << endl;
    }
    else if(left == right)
    {
        cout << "Balanced" << endl;
    }
    if(left < right)
    {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline
N=int(input())
d={}
for i in [0]*N:
 s = ''.join(sorted(input().strip()))
 if s in d:
  d[s]+=1
 else:
  d[s]=1
e=0
for v in d.values():
 if v>=2:
  e+=int(v*(v-1)/2)
print(e)

Measured memory_bytes: 18616
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
using namespace std;

class ACirclePond {
 public:
  void solve(std::istream &in, std::ostream &out) {
      int r;
      in >> r;
      out << setprecision(20) << fixed << 2.0 * r * M_PI << '\n';
  }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ACirclePond solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	while(1){
	  int h,w; cin >> h >>w;
	  if(h==0 && w==0)break;
	  for(int i=0;i<h;i++){
	  	for(int j=0;j<w;j++){
	  		if(j%2==0 && i%2==0){
	  			cout << "#";
	  		}
	  		if(j%2==1 && i%2==0){
	  			cout << ".";
	  		}
	  		if(j%2==1 && i%2==1){
	  			cout << "#";
	  		}
	  		if(j%2==0 && i%2==1){
	  			cout << ".";
	  		}

	  	}
	  	cout << endl;
	  }
	  cout << endl;
	}
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i + 1 < s.size(); i++) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		if (i && s[i - 1] == s[i + 1]) {
			cout << i << " " << i + 2 << endl;
			return 0;
		}
	}
	cout << "-1 -1";
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;


void solve(){
    string s; cin >> s;

    ll n = s.size();
    bool f = true;
    string t = s;
    reverse(ALL(t));
    string s1 = s.substr(0, (n-1)/2);
    string s2 = s.substr((n+3)/2-1, n-(n+3)/2+1);
    string t1, t2;
    t1 = s1;
    t2 = s2;
    reverse(ALL(t1));
    reverse(ALL(t2));

    if(s != t) f = false;
    if(s1 != t1) f = false;
    if(s2 != t2) f = false;
    
    if(f) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}


int main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define M 11
#define N 10001

using namespace std;

int r, c, res, max_res;
bool imap[M][N];
int ret[N];

void solve(int i)
{
	if(i == r){
		res = 0;
		
		for(int j = 0; j < c; j++)
			ret[j] = 0;
	
		for(int j = 0; j < c; j++)
			for(int k = 0; k < r; k++)
				if(imap[k][j])
					ret[j]++;
		
		for(int j = 0; j < c; j++)
			res += max((r - ret[j]), ret[j]);
		max_res = max(res, max_res);
		return;
	}
	solve(i + 1);
	for(int k = 0; k < c; k++)
		imap[i][k] = !imap[i][k];
	solve(i + 1);
}

int main()
{
	while(cin >> r >> c, r, c){
		max_res = 0;
		for(int i = 0; i < r; i++)
			for(int j = 0; j < c; j++)
				cin >> imap[i][j];
		solve(0);
		cout << max_res << endl;
	}
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d))
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod(int A)
{
	 return A%1000000007;
}
void solve()
{
   int n,k;
   cin>>n>>k;
   int total=(n*(n+1));
    total/=2;
    int ans=0;
    for(int i=k;i<=n+1;i++)
    {
    	 int l=(i*(i-1))/2;
    	 int pt=n-(i);
    	 pt=(pt*(pt+1))/2;
    	 
    	 int up=total-pt;
    	 
    	 int rd=up-l+1;
    	 
    	 ans=mod(ans+rd);
    }

    cout<<ans<<" ";


}
main()
{
int t;
t=1;
while(t--)
{
solve();

}
}

Measured memory_bytes: 3636
#N = int(input())
#J,K = map(int,input().split())
#A = list(map(int(input().split())))
#A = [list(map(int(input().split()))) for _ in range(N)]
#for i in range():

N,M,X = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(N)]
ans = 10**10

for i in range(2**N):
    A = []
    c = 0
    B = [0]*M
    for j in range(N):
        if ((i >> j) & 1):
            A.append(j)
    for k in A:
        for l in range(M):
            B[l] += C[k][l+1]
        c += C[k][0]
    if min(B) >= X:
        ans = min(ans,c)
if ans != 10**10:
    print(ans)
else:
    print(-1)
        


Measured memory_bytes: 9044
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int dp[101010];
int rec(Graph &G, int u){
    if(dp[u] != -1) return dp[u];
    if(G[u].empty()) return dp[u] = 0;
    int tmp = 0;
    repe(i, G[u]){
        chmax(tmp, rec(G, i)+1);
    }
    return dp[u] = tmp;
}

int main(){
    fastcin();

    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
    }
    memset(dp, -1, sizeof(dp));
    rep(i, n){
        if(dp[i] == -1) rec(G, i);
    }
    // rep(i, n) cout << dp[i] << endl;
    cout << *max_element(dp, dp+n) << endl;

}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> m;
        while (m % 2 == 0) {
            m /= 2;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	string s,d;
	while(getline(cin,s)){
		for(int j=0;j<26;j++){
			for(int i=0;i<s.size();i++){
				if(s[i]>='a'&&s[i]<='z'){
					s[i]=(s[i]=='z')?'a':s[i]+1;
				}
			}
			if(s.find("the")!=string::npos||s.find("this")!=string::npos||s.find("that")!=string::npos){
				cout<<s<<endl;
			}
		}
	}
	return 0;
}

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

int main(){
	int h, n;
	cin >> h >> n;
	
	int a, ans;
	for(int i=0; i<n; i++){
		cin >> a;
		ans += a;
	}
	
	if(h <= ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=m;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int n,h,w;
    cin >> n>> h>>w;
    int ans=0;
    REP(i,n){
        int a,b;
        cin >> a>>b;
       ans +=  min(a/h,b/w);
    }

    cout <<ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = [a[i]-a[i+1] for i in range(n-1)]
c = [0]
x = 0
for i in range(n-1):
    if b[i] >= 0:
        x += 1
        c.append(x)
    else:
        x = 0
print(max(c))

Measured memory_bytes: 14992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nums = new int[6];
        for (int i = 0; i < 6; i++) {
            nums[i] = sc.nextInt();
        }
        sc.nextLine();
        String line = sc.nextLine();
        Dice dice = new Dice(nums);
        for (int i = 0, l = line.length(); i < l; i++) {
            char o = line.charAt(i);
            if (o == 'S') {
                dice.turnSouth();
            } else if (o == 'E') {
                dice.turnEast();
            } else if (o == 'W') {
                dice.turnWest();
            } else if (o == 'N') {
                dice.turnNorth();
            }
        }
        System.out.println(dice.getUp());
    }
}

class Dice {

    public static byte UP = 0;
    public static byte FRONT = 1;
    public static byte RIGHT = 2;
    public static byte LEFT = 3;
    public static byte BACK = 4;
    public static byte DOWN = 5;
    private int[] nums;
    private byte[] ids;

    /**
     *
     * @param nums
     * - 0 - -
     * 3 1 2 4
     * - 5 - -
     */
    public Dice(int[] nums) {
        this.nums = nums;
        this.ids = new byte[]{ 0, 1, 2, 3, 4, 5 };
    }

    public int getUp() { return nums[ids[UP]]; }
    public int getDown() { return nums[ids[DOWN]]; }
    public int getRight() { return nums[ids[RIGHT]]; }
    public int getLeft() { return nums[ids[LEFT]]; }
    public int getFront() { return nums[ids[FRONT]]; }
    public int getBack() { return nums[ids[BACK]]; }

    public void turnDisp(byte[] order) {
        byte tmp = ids[order[0]];
        int l = order.length;
        for (int i = 1; i < l; i++) {
            ids[order[i - 1]] = ids[order[i]];
        }
        ids[order[l - 1]] = tmp;
    }

    /**
     * turn{FaceName} メソッド
     * FaceName を中心に時計回り
     */
    public void turnFront() { turnDisp(new byte[]{ UP, LEFT, DOWN, RIGHT }); }
    public void turnBack() { turnDisp(new byte[]{ UP, RIGHT, DOWN, LEFT }); }
    public void turnLeft() { turnDisp(new byte[]{ UP, BACK, DOWN, FRONT }); }
    public void turnRight() { turnDisp(new byte[]{ UP, FRONT, DOWN, BACK }); }
    public void turnUp() { turnDisp(new byte[]{ FRONT, RIGHT, BACK, LEFT }); }
    public void turnDown() { turnDisp(new byte[]{ FRONT, LEFT, BACK, RIGHT }); }

    /** optional aliases */
    public void turnFrontRev() { turnBack(); }
    public void turnBackRev() { turnFront(); }
    public void turnLeftRev() { turnRight(); }
    public void turnRightRev() { turnLeft(); }
    public void turnUpRev() { turnDown(); }
    public void turnDownRev() { turnUp(); }

    /**
     * 手前をFrontと見て
     */
    public void turnToUp() { turnLeft(); }
    public void turnToDown() { turnLeftRev(); }
    public void turnToLeft() { turnUp(); }
    public void turnToRight() { turnUpRev(); }

    /**
     * 手前を南, 奥(前進方向)を北とした場合
     */
    public void turnSouth() { turnToUp(); }
    public void turnNorth() { turnToDown(); }
    public void turnEast() { turnFront(); }
    public void turnWest() { turnFrontRev(); }
}

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

#define MAX_DIGIT 80

void add(char *buf1, char *buf2){
	int len1 = strlen(buf1);
	int len2 = strlen(buf2);
	if(len1 > MAX_DIGIT || len2 > MAX_DIGIT){
		printf("overflow\n");
		return;
	}
	
	int out[MAX_DIGIT + 2];
	int i = 0;
	int carry = 0;
	while(len1 > 0 || len2 > 0){
		out[i] = carry;
		if(len1 > 0){
			len1--;
			out[i] += buf1[len1] - '0';
		}
		if(len2 > 0){
			len2--;
			out[i] += buf2[len2] - '0';
		}
		if(out[i] >= 10){
			carry = 1;
			out[i] -= 10;
		}else{
			carry = 0;
		}
		i++;
	}
	if(carry > 0){
		out[i] = carry;
	}else{
		i--;
	}
	if(i >= MAX_DIGIT){
		printf("overflow\n");
		return;
	}
	for(; i >= 0; i--){
		printf("%d", out[i]);
	}
	printf("\n");
}

int main(){
	int n;
	char buf1[10000], buf2[10000];
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%s", buf1);
		scanf("%s", buf2);
		add(buf1, buf2);
	}
	
	return 0;
}

Measured memory_bytes: 1056
/**
 *	author:		Yoseph Weissman
 *	created:	17.06.2020 09:59:13
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0, j = (int)s.length()-1; i < j; ++i, --j) {
		if (s[i] != s[j])
			++cnt;
	}
	cout << cnt << "\n";
	return 0;
}


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

#define int long long
typedef pair<int, int> P;

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int N, C;
int A[440], B[440];
int dp[440][440];
int imos[440][440];
int mod = 1e9 + 7;
signed main() {
    for (int i = 0; i <= 400; i++) {
        imos[i][0] = 1;
        for (int j = 1; j <= 400; j++) {
            (imos[i][j] = imos[i][j - 1] * i) %= mod;
        }
        for (int j = 0; j <= 400; j++) {
            (imos[i][j] += imos[i - 1][j]) %= mod;
        }
    }
    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= C; j++) {
            for (int k = 0; k <= j; k++) {
                (dp[i][j] += dp[i - 1][k] * ((imos[B[i - 1]][j - k] - imos[A[i - 1] - 1][j - k] + mod) % mod) % mod) %= mod;
            }
        }
    }
    cout << dp[N][C] << endl;
    return 0;
}

Measured memory_bytes: 3072
N = int(input())
dic, rst = {}, []
for i in range(N):
    S = input()
    if S in dic:
        dic[S] += 1
    else:
        dic[S] = 1
max_val = max(dic.values())
[ rst.append(key) for key, val in dic.items() if val == max_val ]
[ print(i) for i in sorted(rst) ]

Measured memory_bytes: 37840
def main(n, s: list, m, t: list):
    choices = set(s + t)

    ans = [0]

    for choice in choices:
        ans_t = 0
        for _s in s:
            if choice == _s:
                ans_t += 1
        for _t in t:
            if choice == _t:
                ans_t -= 1

        ans.append(ans_t)

    print(max(ans))


if __name__ == "__main__":
    n = int(input())
    s = [input() for _ in range(n)]
    m = int(input())
    t = [input() for _ in range(m)]

    main(n, s, m, t)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int main(){
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<int> L(M), R(M);
	for(int i=0;i<M;i++){
		cin >> L[i] >> R[i];
	}
	vector<int> p(Q),q(Q);
	for(int i=0;i<Q;i++){
		cin >> p[i] >> q[i];
	}
	int X[502][502];
	int C[502][502];
	for(int i=0;i<M;i++){
		X[L[i]][R[i]]++;
	}
	for(int i=0;i<N+1;i++){
		for(int j=0;j<N+1;j++) C[i][j] = C[i][j-1] + X[i][j];
	}
	for(int i=0;i<Q;i++){
		int sum = 0;
		for(int j=p[i];j<=q[i];j++) sum += C[j][q[i]] - C[j][p[i] - 1];
		cout << sum << endl;
	}
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,m;
    cin>>a>>b>>c>>d;
    m=(a*c);
    m=max(m,(a*d));
    m=max(m,(b*c));
    m=max(m,(b*d));

    cout<<m<<endl;
}


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

void print(int a[], int n) {
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << a[i];
	}
	cout << endl;
}

void insertionSort(int a[],int n) {
	print(a, n);
	for (int i = 1; i <= n - 1; i++) {
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		print(a,n);
	}
}

int main() {
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	insertionSort(a, n);

	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

ll dp[N][3];
int32_t main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll n, k, S, R, P;
    cin >> n >> k >> R >> S >> P;
    string t;
    cin >> t;
    t = '.' + t;
    for (int i = 1; i <= k; i ++) {
    	if (t[i] == 's') {
    		dp[i][0] = R;
		}
		if (t[i] == 'p') {
			dp[i][1] = S;
		}
		if (t[i] == 'r') {
			dp[i][2] = P;
		}
	}
	for (int i = k + 1; i <= n; i ++) {
		ll rr = max({dp[i -k][0], dp[i -k][1], dp[i - k][2]});
		if (t[i] == 's') {
			ll res = max(dp[i - k][1], dp[i - k][2]);
			dp[i][0] = max(R + res, max(res, dp[i - k][0]));
			dp[i][1] = rr;
			dp[i][2] = rr;
		}
		if (t[i] == 'p') {
			ll res = max(dp[i - k][0], dp[i - k][2]);
			dp[i][1] = max(S + res, max(res, dp[i - k][1]));
			dp[i][2] = rr;
			dp[i][0] = rr;
		}
		if (t[i] == 'r') {
			ll res = max(dp[i - k][1], dp[i - k][0]);
			dp[i][2] = max(P + res, max(res, dp[i - k][2]));
			dp[i][1] = rr;
			dp[i][0] = rr;
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; i ++) {
		ll res = max({dp[i][0], dp[i][1], dp[i][2]});
		if (i + k> n) ans += res;
		//if (i + k > n) cout << res<< endl; 
	}
	cout << ans<< endl;
    return (0) ;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


int main(){
    int r, D, x;
    cin >> r >> D >> x;
    for (int i = 0; i < 10; ++i)
    {
        x = r * x - D;
        cout << x << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
p = gets.split.map(&:to_i)
result = 0
(1..n-2).each do |i|
  ary = [p[i-1],p[i],p[i+1]]
  if ary.max != p[i] && ary.min != p[i]
    result += 1
  end
end
puts result

Measured memory_bytes: 3836
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Pair = Tuple!(long, "flag", long, "num");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

auto dp = new long[100_100];
void main()
{
    auto n = lread();
    auto h = aryread();
    dp[1] = abs(h[1] - h[0]);
    foreach (i; iota(2, n))
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    dp[n - 1].writeln();
}


Measured memory_bytes: 5148
#include<stdio.h>
 
int F[45] = {};
 
int fib(int n){
  int u, v;
  if(F[n] != 0) return F[n];
  else{ 
    if(n == 0 || n == 1) F[n] = 1;
    else{
      u = fib(n - 1);
      v = fib(n - 2);
      F[n] = u + v;
    }
  }
  return F[n];
}
 
int main(){
  int n;
  scanf("%d", &n);
  printf("%d\n", fib(n));  
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int n;
int arr[200001];
int ans[200001];
vi adj[200001];

vi tail;

void dfs(int i, int p)
{
	int ls0 = tail[0];
	int lsl = tail.back();
	int id = lower_bound(tail.begin(), tail.end(), arr[i]) - tail.begin();
	int old_v;

	if (arr[i] < tail[0])
		tail[0] = arr[i];

	else if (arr[i] > tail.back())
		tail.pb(arr[i]);

	else
	{
		old_v = tail[id];
		tail[id] = arr[i];
	}

	ans[i] = tail.size();

	for (auto el : adj[i])
		if (el != p)
			dfs(el, i);

	if (arr[i] < ls0)
		tail[0] = ls0;

	else if (arr[i] > lsl)
		tail.pop_back();

	else
		tail[id] = old_v;

}

int32_t main()
{
	FIO;
	cin >> n;

	for (int i = 0; i < n; ++i)
		cin >> arr[i];

	for (int i = 0; i < n - 1; ++i)
	{
		int u, v; cin >> u >> v;
		u--, v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	ans[0] = 1;
	tail.pb(arr[0]);

	for (int i : adj[0])
		dfs(i, 0);

	for (int i = 0; i < n; ++i)
		cout << ans[i] << '\n';

	return 0;
}

Measured memory_bytes: 34964
#include <bits/stdc++.h>
    using namespace std;
    #define INF 2000000000
    typedef long long int ll;
    typedef pair<ll,ll> ii;
    typedef pair<ii,ll> iii;
    typedef vector<ll> vi;
    typedef vector<ii> vii;
    #define getbit(n,i) (((n)&(1<<(i)))!=0)
    #define setbit0(n,i) ((n)&(~(1<<(i))))
    #define setbit1(n,i) ((n)|(1<<(i)))
    #define togglebit(n,i) ((n)^(1<<(i)))
    #define lastone(n) ((n)&(-(n)))
    #define read freopen("debug\\in.txt","r",stdin)
    #define write freopen("debug\\out.txt","w",stdout)
    #define fi first
    #define se second
    #define getI(a) scanf("%d",&a)
    #define getII(a,b) scanf("%d%d",&a,&b)
    #define PI (acos(-1))
    #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
    #define mod (1000000007)
    #define asz 500005
    #define pb push_back
    #define ppf pop_front
    #define ppb pop_back
    #define pf push_front
    int a[200005];
    int b[200005];
    int main()
    {
        fastread;
        int n,i,j,k,l,m;
        cin>>n>>m;
        for(i=1;i<=m;i++){
        	string s;
        	cin>>k>>s;
        	if(s=="AC")
        	a[k]=1;
        	else{
        		if(a[k]==0)
        		b[k]++;
			}
		}
		int sum=0;
		int cnt=0;
		for(i=1;i<=n;i++){
			if(a[i]==1)
			{
			  cnt++;
			  sum+=b[i];
		    }
		}
		cout<<cnt<<" "<<sum<<endl;
    	return 0;
    }

Measured memory_bytes: 1024
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    string ans="";
    cin >> s>>t;
    for (int i = 0; i < s.size(); i++)
    {
        ans+=s[i];
        if(i!=t.size())
        ans+=t[i];
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
/* - - - - - - - - - - - - - - -
	User : 		VanishD
	problem :
	Points : 	
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define 	ll 		long long
using namespace std;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
int read(){
	int tmp = 0, fh = 1; char ch = getchar();
	while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
	return tmp * fh;
}
const int N = 5010, P = 1e9 + 7;
struct Edge{
	int data, next;
}e[N * 2];
int f[N][N][2], g[N][2], size[N], head[N], place, mul[N], n, ans;
void build(int u, int v){
	e[++place].data = v; e[place].next = head[u]; head[u] = place;
}
void dp(int x, int fa){
	f[x][1][0] = 1; size[x] = 1;
	for (int ed = head[x]; ed != 0; ed = e[ed].next)
		if (e[ed].data != fa){
			dp(e[ed].data, x);
			int y = e[ed].data;
			for (int i = 1; i <= size[x] + size[e[ed].data]; i++)
				g[i][0] = g[i][1] = 0;
			for (int i = 1; i <= size[x]; i++){
				for (int j = 1; j <= size[y]; j++){
					g[i + j][0] = (g[i + j][0] + 1ll * f[y][j][0] * f[x][i][0] + 1ll * f[y][j][1] * f[x][i][1]) % P;
					g[i + j][1] = (g[i + j][1] + 1ll * f[y][j][1] * f[x][i][0] + 1ll * f[y][j][0] * f[x][i][1]) % P;
					if (j % 2 == 0){
						g[i][1] = (g[i][1] + 1ll * f[y][j][0] * mul[j - 1] % P * f[x][i][0]) % P;
						g[i][1] = (g[i][1] + 1ll * f[y][j][1] * mul[j - 1] % P * f[x][i][1]) % P;
						g[i][0] = (g[i][0] + 1ll * f[y][j][0] * mul[j - 1] % P * f[x][i][1]) % P;
						g[i][0] = (g[i][0] + 1ll * f[y][j][1] * mul[j - 1] % P * f[x][i][0]) % P;
					}
				}
			}
			size[x] = size[x] + size[e[ed].data];
			for (int i = 1; i <= size[x]; i++)
				f[x][i][0] = g[i][0], f[x][i][1] = g[i][1];
		}
}
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for (int i = 1; i < n; i++){
		int u = read(), v = read();
		build(u, v); build(v, u);
	}
	mul[1] = 1; for (int i = 3; i <= n; i++) mul[i] = 1ll * mul[i - 2] * i % P;
	dp(1, 0);
	for (int i = 1; i <= n; i++){
		if (i % 2 == 0){
			int tmp = 1ll * mul[i - 1] * (f[1][i][0] - f[1][i][1]) % P;
			ans = ((ans + tmp) % P + P) % P;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 195072