akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+10;
const int  mod=1e9+7;
int sum[maxn];
ll dp[110][5][5][5];
int main()
{
    int n;
    ll ans=0;
    scanf("%d",&n);
    for(register int i=0; i<4; i++)
        for(register int j=0; j<4; j++)
            for(register int k=0; k<4; k++)
            {
                if(i==0&&j==1&&k==2||i==0&&j==2&&k==1||i==2&&j==0&&k==1)
                    continue;
                dp[3][i][j][k]=1;

            }
    for(register int t=4; t<=n; t++)
        for(register int i=0; i<4; i++)
            for(register int j=0; j<4; j++)
                for(register int k=0; k<4; k++)
                    for(register int h=0; h<4; h++)
                    {
                        if(i==0&&j==1&&k==2||i==0&&j==2&&k==1||i==2&&j==0&&k==1)
                            continue;//i,j,k
                        if(j==0&&k==1&&h==2||j==0&&k==2&&h==1||j==2&&k==0&&h==1)
                            continue;
                        if(i==0&&k==2&&h==1||i==0&&j==2&&h==1)
                            continue;
                        dp[t][j][k][h]=(dp[t][j][k][h]+dp[t-1][i][j][k])%mod;
                    }
    for(register int i=0; i<4; i++)
        for(register int j=0; j<4; j++)
            for(register int k=0; k<4; k++)
                ans+=(dp[n][i][j][k]);
    printf("%lld\n",ans%mod);

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const char sp = ' ';
int N, a, b;
vector<int>v[100000];
bool vis[100000];

int dfs(int x) {
	vis[x] = true;
	int c = 0;
	bool f = false;
	for (int i : v[x]) {
		if (!vis[i]) {
			int t = dfs(i);
			if (t) {
				c += t;
			}
			else {
				if (f) {
					++c;
				}
				else {
					f = true;
				}
			}
		}
	}
	return c;
}

int main() {
	cin >> N;
	for (int i = 1; i < N; ++i) {
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int i = 0; i < N; ++i) {
		if (v[i].size() >= 3) {
			cout << dfs(i) << endl;
			return 0;
		}
	}
	cout << 1 << endl;
}

Measured memory_bytes: 8320
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int n = fs.nextInt();
		int[] aArr = fs.nextIntArr(n);
		
		Arrays.sort(aArr);
		
		long ans = 0;
		
		Comparator<Aida> aidaComparator = Comparator.comparing(Aida::getValue);
		ArrayDeque<Aida> aidaQue = new ArrayDeque<>();
		
		aidaQue.add(new Aida(aArr[n-1], aArr[n-1]));
		for(int i = n-2; i >= 0; i--) {
			
			Aida leftAida = aidaQue.poll();
			int aVal = aArr[i];
			ans += leftAida.getValue();
			aidaQue.add(new Aida(leftAida.one, aVal));
			aidaQue.add(new Aida(leftAida.two, aVal));
		}
		
		System.out.println(ans);
	}

	class Aida {
		
		int one;
		int two;
		
		Aida(int one, int two){
			this.one = one;
			this.two = two;
		}
		
		int getValue() {
			return Math.min(one, two);
		}
	}

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 62496
import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools
from heapq import heappush, heappop, heappushpop, heapify, heapreplace
#input = sys.stdin.readline

N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for _ in range(M)]
G1 = collections.defaultdict(lambda: collections.defaultdict(int))
G2 = collections.defaultdict(lambda: collections.defaultdict(int))

for u, v, a, b in UVAB:
    u -= 1
    v -= 1
    G1[u][v] = G1[v][u] = a
    G2[u][v] = G2[v][u] = b


def dijkstra(V, G, start):
    INF = float('inf')
    D = [INF for _ in range(V)]
    D[start] = 0
    H = [(0, start)]
    while H:
        du, u = heappop(H)
        if D[u] < du:
            continue
        for v, d in G[u].items():
            if D[v] > du + d:
                D[v] = du + d
                heappush(H, (D[v], v))
    return D


D1 = dijkstra(N, G1, S - 1)
D2 = dijkstra(N, G2, T - 1)

D = [10**15 - sum(_) for _ in zip(D1, D2)]
for i in range(N - 1, 0, -1):
    D[i - 1] = max(D[i - 1], D[i])
print(*D, sep='\n')


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

bool check(vector<bool> marked, vector<int> row)
{
    for (auto n : row)
    {
        if (!marked[n])
            return false;
    }
    return true;
}

int main()
{
    map<int, int> nums;
    vector<bool> marked(9, false);
    for (int i = 0; i < 9; i++)
    {
        int A;
        cin >> A;
        nums[A] = i;
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int B;
        cin >> B;
        if (nums.find(B) == nums.end())
        {
            continue;
        }
        auto loc = nums[B];
        marked[loc] = true;
    }
    for (int i = 0; i < 3; i++)
    {
        if (check(marked, vector<int>{3 * i, 3 * i + 1, 3 * i + 2}))
        {
            cout << "Yes" << endl;
            return 0;
        }
        if (check(marked, vector<int>{i, i + 3, i + 6}))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (check(marked, vector<int>{0, 4, 8}))
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (check(marked, vector<int>{2, 4, 6}))
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ACantWaitForHoliday {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;
        map<string, int> m;
        m["SUN"] = 7;
        m["MON"] = 6;
        m["TUE"] = 5;
        m["WED"] = 4;
        m["THU"] = 3;
        m["FRI"] = 2;
        m["SAT"] = 1;
        cout << m[s] << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ACantWaitForHoliday solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC172
{
    using static Ex;
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_A();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var a = ReadInt;
            (a + a * a + a * a * a).Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
        }
    }

    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }



        public static bool Mins<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
        public static bool Maxs<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
        public static void Swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
        public static void Swap<T>(List<T> list, int i, int j) { T tmp = list[j]; list[j] = list[i]; list[i] = tmp; }

        public static long Lcm(int x, int y) { return x / Gcd(x, y) * y; }
        public static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); }
        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var v = new string[N]; for (long i = 0; i < N; ++i) v[i] = Read; return v; }
        public static int[] ReadIntArray(long N) { var v = new int[N]; for (long i = 0; i < N; ++i) v[i] = ReadInt; return v; }
        public static long[] ReadLongArray(long N) { var v = new long[N]; for (long i = 0; i < N; ++i) v[i] = ReadLong; return v; }

        public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
        public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
        public static (T, T, T, T) ToTpl4<T>(this T[] v) { return (v[0], v[1], v[2], v[3]); }
        public static (T, T, T, T, T) ToTpl5<T>(this T[] v) { return (v[0], v[1], v[2], v[3], v[4]); }
    }
}


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

int main()
{
  int n[3];
  int temp, i = 0;
  while(cin >> temp)
  {
    n[i] = temp;
    i++;
  }
  cout << n[2]<< " " << n[0] << " " << n[1] << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;

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

    string res;
    if(a > 0 && b > 0) {
        res = "Positive";
    } else if(a <= 0 && b >= 0) {
        res = "Zero";
    } else {
        if((abs(a) - abs(b) + 1) % 2 == 0) {
            res = "Positive";
        } else {
            res = "Negative";
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3508
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,ans=0;
	cin>>a>>b>>c>>d;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(i*500+j*100+k*50==d) ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <cmath>
#include <queue>
typedef long long ll;
using namespace std;

int main(void){
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    vector<char> left;
    vector<char> right;
    
    int normal = 1;
    int q, f;
    char c;
    for(int i = 0; i < Q; i++){
        cin >> q;
        if(q==1) normal *= -1;
        else{
            cin >> f >> c;
            if(f==1) {
                if(normal==1) left.push_back(c);
                else right.push_back(c);
            }
            else {
                if(normal==1) right.push_back(c);
                else left.push_back(c);
            }
        }
    }
    
    string ans = "";

    if(normal==1) {
        for(int i = left.size()-1; i >=0; i--) ans +=  left[i];
        ans += S;
        for(int i = 0; i < right.size(); i++) ans += right[i];
    } else {
        for(int i = right.size()-1; i >=0; i--) ans +=  right[i];
        reverse(S.begin(), S.end());
        ans += S;
        for(int i = 0; i < left.size(); i++) ans += left[i];
    }
    cout << ans << endl;
    
}



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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	vll v[26];
	string a,b;
	cin>>a>>b;
	n=a.length(),m=b.length();
	rep(i,0,n) v[a[i]-'a'].pb(i);
	ll pr=-1;
	cnt=0;
	rep(i,0,m){
		k=b[i]-'a';
		if(v[k].empty()) ret(-1)
		ll pos=ubnd(all(v[k]),pr)-v[k].begin();
		if(pos==v[k].size()) cnt++,pr=v[k][0];
		else pr=v[k][pos];
	}	
	ret(cnt*n+pr+1);
	return 0;
}

Measured memory_bytes: 1736
#!/usr/bin/env python3
import sys
import collections

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, K: int, Q: int, A: "List[int]"):
    result = {n:0 for n in range(N)}
    for a in A:
        result[a-1] += 1
    for k, v in result.items():
        if K - Q + result[k] <= 0:
            print('No')
        else:
            print('Yes')
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(N, K, Q, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19424
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None
mintime = 9999

def f(current, time, draws):
    global mintime

    if time > mintime:
        return 999999

    if current == 0:
        mintime = min(mintime, time)
        return time

    i = 0
    while draws[i] > current:
        i += 1

    if i + 1 == len(draws):
        return f(current - draws[i], time + 1, draws)
    else:
        return min(f(current-draws[i], time+1, draws), f(current-draws[i+1], time+1, draws))

def main():
    N = int(input())
    draws = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]

    print(f(N, 0, draws))

main()


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,C=0;
  cin>>N;
  int A[N-1];
  for(int i=0;i<N;i++){
      cin>>A[i];
  }
  while(1){
      bool odd=false;
      for(int i = 0;i<N;i++){
          if(A[i]%2){
              odd=true;
          }
      }
      if(odd) break;
      C++;
      for(int i=0;i<N;i++){
          A[i]/=2;
      }
  }
  cout<<C<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

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

    string S;
    cin >> S;
    int N = S.size();
    int l = 0;
    int r = 0;

    int ans = 0;
    while (l < N) {
        int r = l;
        while (r < N) {
            if (S[r] != 'A' && S[r] != 'C' && S[r] != 'G' && S[r] != 'T') {
                ans = max(ans, r - l);
                break;
            } else if (r == N - 1) {
                ans = max(ans, r - l + 1);
            }
            r++;
        }
        l = r + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, cnt,tmp;
	cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> tmp;
		if (tmp != i)cnt++;
	}
	if (cnt > 2)cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338327950L
 
long double a,b,h,m,c,d1,d2;
int main()
{
	cin>>a>>b>>h>>m;
	d1=(long double)m/360.0+(long double)h/6;
	d2=(long double)m/30;
	d2=(d1-d2);
	c=sqrt(2*a*b)*sqrt((a*a+b*b)/(2*a*b)-cos(d2*PI));
	cout<<fixed<<setprecision(20)<<c; 
}


Measured memory_bytes: 4080
from collections import Counter

s=input()
c=Counter(s)
#test_s=[k for k,v in c.items() if v==max(c.values())]
test_s=c.keys()
ans=100
for i in test_s:
 ss=i+s+i
 inx=[j for j,x in enumerate(ss) if x==i]
 d_max=0
 for k in range(len(inx)-1):
  d_max=max(d_max,inx[k+1]-inx[k]-1)
 ans=min(ans,d_max)

print(ans)

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

int main() {
  int k;
  cin >> k;
  int a = 7;
  int cnt = 1;

  while (a % k != 0) {
    a = a - a / k * k;
    a = a * 10 + 7;
    cnt++;
    if (cnt >= 10000000) {
      cnt = -1;
      break;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3632
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    new_s=""
    i=0
    if n==0:
        print(0)
        sys.exit()
    while n:
        x=(n>>i)&1
        new_s=str(x)+new_s
        n-=x*(-2)**i
        i+=1
    print(new_s)


if __name__=='__main__':
    main()

Measured memory_bytes: 38576
import java.util.*;
import java.io.*;
class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String []s = br.readLine().split(" ");

        int N = Integer.parseInt(s[0]);
        int W = Integer.parseInt(s[1]);

        int []weigths = new int[N];
        long []values = new long[N];
        

        for(int i=0; i < N; ++i) {
            s = br.readLine().split(" ");
            weigths[i] = Integer.parseInt(s[0]);
            values[i] = Integer.parseInt(s[1]);
        }



        long [][]dp = new long[N+1][W+1];

        for(int i=0; i <= N; ++i)
            dp[i][0] = 0;

        for(int i=0; i <= W; ++i)
            dp[0][i] = 0;

        for(int i=1; i <= N; ++i)
            for(int j=1; j <= W; ++j) {
                if (j - weigths[i-1] >= 0)
                    dp[i][j] = Math.max(dp[i-1][j], values[i-1] + dp[i-1][j - weigths[i-1]]);
                else dp[i][j] = dp[i-1][j];
            }

        System.out.println(dp[N][W]);
    }
}

Measured memory_bytes: 132212
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;



int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int N;
  cin >> N;
  map <int,int> memo;
  int maxd = 0;
  rep(i,N){
    int x;
    cin >> x;
    memo[x] += 1;
    maxd = max(maxd, x);
  }
  if (maxd % 2 == 0) {
    for (int d = maxd; d >= maxd/2 + 1; d--) {
      if (memo[d] < 2) {
        cout << "Impossible\n";
        return 0;
      }
    }
    if (memo[maxd/2] != 1) {
      cout << "Impossible\n";
      return 0;
    }
    for (int i = 0; i < maxd / 2; i++) {
      if (memo.find(i) != memo.end()) {
        cout << "Impossible\n";
        return 0;
      }
    }
  }else{
    for (int d = maxd; d >= maxd / 2 + 2; d--) {
      if (memo[d] < 2) {
        cout << "Impossible\n";
        return 0;
      }
    }
    if (memo[(maxd + 1) / 2] != 2) {
        cout << "Impossible\n";
        return 0;
    }
    for (int i = 0; i < maxd / 2; i++) {
      if (memo.find(i) != memo.end()) {
        cout << "Impossible\n";
        return 0;
      }
    }
  }
  cout << "Possible\n";
  return 0;
}



Measured memory_bytes: 256
import sys

N, x = map(int, input().split())
if x == 1 or x == 2 * N - 1:
    print("No")
    sys.exit()
if N == 2:
    print("Yes")
    print(1)
    print(2)
    print(3)
    sys.exit()

print("Yes")
n = 2 * N - 1
ans = [None] * n
tmp = ans[n//2-1:n//2+3]
# print(tmp)
if x != 2 * N - 2:
    tmp[0] = x + 1
    tmp[1] = x
    tmp[2] = x - 1
    tmp[3] = x + 2
else:
    tmp[0] = x - 1
    tmp[1] = x
    tmp[2] = x + 1
    tmp[3] = x - 2
cnt = 1

ans[n//2-1:n//2+3] = tmp
for i in range(n):
    if x != 2 *  N - 2:
        if cnt == x-1:
            cnt += 4
    else:
        if cnt == x-2:
            cnt += 4
    if ans[i] is None:
        ans[i] = cnt
        cnt += 1

for i in ans:
    print(i)


Measured memory_bytes: 12560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ar[500005];
int main()
{
    ll a;
    cin >> a;
    for(int i=1;i<=a;i++)
    {
        cin>>ar[i];
    }
    ar[a+1]=99999999999;
    ll mx=0,cnt=0;
    for(int i=2;i<=a+1;i++)
    {
        if(ar[i]>ar[i-1])
        {
            mx=max(cnt,mx);
            cnt=0;
        }
        else
        {
            cnt++;
        }
    }
    cout << mx << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

bool check_A(string str){
	if(str.size() < 6 || str.size() % 2 == 1){
		return false;
	}
	if(str.substr(0, 2) != ">'"){
		return false;
	}
	int count = 0;
	for(int i = 2; i < (str.size() - 4) / 2 + 2; i++){
		if(str[i] != '='){
			return false;
		}
	}
	if(str[str.size() / 2] != '#'){
		return false;
	}
	for(int i = str.size() / 2 + 1; i <= str.size() - 2; i++){
		if(str[i] != '='){
			return false;
		}
	}
	if(str[str.size() - 1] != '~'){
		return false;
	}
	return true;
}

bool check_B(string str){
	if(str.size() < 6 || str.size() % 2 == 1){
		return false;
	}
	if(str.substr(0, 2) != ">^"){
		return false;
	}
	for(int i = 2; i < str.size() - 2; i += 2){
		if(str.substr(i, 2) != "Q="){
			return false;
		}
	}
	if(str.substr(str.size() - 2, 2) != "~~"){
		return false;
	}
	return true;
}

int main(){
	
	int n;
	
	string str;
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		cin >> str;
		if(check_A(str)){
			printf("A\n");
		}else if(check_B(str)){
			printf("B\n");
		}else{
			printf("NA\n");
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e6;
    
     int mod= 1e9+7;
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
   
   void solve() {
	     string s;
         cin>>s;
         
         int n=sz(s);
         
         vector<vi> dp(n+1,vi (13,0));
	     
         dp[0][0]=1;
         
         rep(i,0,n){
             
             rep(j,0,10){
                 
                 int tp=s[i]-'0';
                 
                 if(s[i]=='?')
                   tp=j;
                 
                 rep(k,0,13){
                     
                     int nvt=(10*k+tp)%13;
                     dp[i+1][nvt]+=dp[i][k];
                     dp[i+1][nvt]%=mod;
                 }
                 
                 if(s[i]!='?') break;  
             }
         }
         
         //~ rep(i,0,n+1){
          //~ rep(j,0,13)
           //~ cout<<dp[i][j]<<" ";
           //~ cout<<endl;
         //~ }
         
         cout<<dp[n][5]<<endl;  
       
       }
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 13648
// Problem : 
// 			A - Rainy Season
// 			
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
	“Whether you think you can, or you think you can’t – you’re right” - Henry Ford 
*/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
	string s;
	cin >> s;
	ll ls = 0, ans = 0;
	for(int i = 0; i < 3; i++) {
		if(s[i] == 'R') ls++;
		else ls = 0;
		ans = max(ans, ls);
	}
	cout << ans << endl;
}

int main()
{
	fast;
   ll t = 1;
   // cin >> t;
   while(t--) {
   	solve();
   }
	return 0;
}


Measured memory_bytes: 3652
/*
   AtCoder Submission
*/

#include<bits/stdc++.h>

using namespace std;

/* typedefs */
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;

    int x= 0;
    for(char c : s){
        if(c == '+'){
            x++;
        } else if (c=='-'){
            x--;
        }
    }

    cout<<x<<endl;

    return 0;
}       


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 25;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

int n, v[MAXN], c[MAXN], dp[MAXN][55*MAXN][55*MAXN];

int solve(int i, int val, int cost) {
	if(i == n) return val - cost;
	int &ret = dp[i][val][cost];
	if(ret != -1) return ret;
	return ret = max(solve(i + 1, val + v[i], cost + c[i]), solve(i + 1, val, cost));
}

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

	memset(dp, -1, sizeof dp);

	cin >> n;

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

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

	cout << solve(0, 0, 0) << endl;

	return 0;
}


Measured memory_bytes: 184832
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int a, b;
    cin>>a>>b;
    int x0 = ceil((double)a / 0.08);
    int y0 = ceil((double)b / 0.1);
    double x1 = (double)(a+1) / 0.08;
    double y1 = (double)(b+1) / 0.1;
    int res = max(x0, y0);
    if (res < x1 && res < y1) {
        cout<<res<<endl;
    } else {
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

using ipair = pair<int,int>;

int INF = 1e9+7;

using ipair = pair<int,int>;
bool operator>(const ipair a,const ipair b){return a.first > b.first;}


bool check(string s, string t, int base_idx){
  if(s.size() < base_idx+t.size()-1){
    return false;
  }
  rep(i, t.size()){
    if(s[base_idx+i] == '?') continue;
    if(s[base_idx+i] == t[i]) continue;

    return false;
  }

  return true;
}

int main(){
  string str, T;
  cin >> str;
  cin >> T;

  int n = str.size();
  int t = T.size();

  int insert_idx = -1;
  rep(i, n){
    if(check(str, T, i)){
      insert_idx = i;
    }
  }

  if(insert_idx == -1){
    cout << "UNRESTORABLE" << endl;
  }else{
    // 
    rep(i, t) str[insert_idx+i] = T[i];
    //
    rep(i, n) str[i] = ((str[i]=='?') ? 'a': str[i]);  

    cout << str << endl;
  }

  return 0;

}


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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i].first;
    A[i].second = i+1;
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) cout << A[i].second << " ";
  cout << endl;
}


Measured memory_bytes: 3932
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n : usize)-> UnionFind {
        let mut par = Vec::with_capacity(n);
        for i in 0..n {
            par.push(i);
        }
        UnionFind {
            parent: par,
            size: vec![1; n]
        }
    }

    fn union(&mut self, l: usize, r: usize) {
        let mut lp = self.get_par(l);
        let mut rp = self.get_par(r);

        if lp != rp {
            self.parent[lp] = rp;
            self.size[rp] += self.size[lp];
        }
        
    }

    fn get_par(&mut self, tar: usize) -> usize {
        let mut par = tar;
        while self.parent[par] != par {
            par = self.parent[par];
        }
        self.parent[tar] = par;
        par
    }

    fn get_par_size(&mut self, tar: usize) -> usize {
        let par = self.get_par(tar);
        self.size[tar]
    }

    fn is_parent(&self, x: usize) -> bool {
        self.parent[x] == x
    }
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let m = line[1];

    let mut uf = UnionFind::new(n);
    for i in 0..m {
        let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = line[0] - 1;
        let b = line[1] - 1;

        uf.union(a,b);
    }

    let mut ans = 0;
    for i in 0..n {
        if uf.is_parent(i) {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef int ll;

ll N, A[5000], B[5000];

bool a[5000], b[5000];
ll p[5000], q[5000], ans[5000];
pair<ll, ll> s[5000], t[5000];

ll f(ll u, ll v) {
  ll ret = 0;

  ll j = 0;
  while (j < N && (b[q[j]] || q[j] == v)) j++;

  REP(i, 0, N) {
    if (a[p[i]] || p[i] == u) continue;
    if (j < N && A[p[i]] < B[q[j]]) {
      j++;
      while (j < N && (b[q[j]] || q[j] == v)) j++;
      ret++;
    }
  }
  return ret;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, N) cin >> B[i];

  {
    pair<ll, ll> f[5000], g[5000];
    REP(i, 0, N) f[i] = make_pair(A[i], i);
    REP(i, 0, N) g[i] = make_pair(B[i], i);
    sort(f, f + N, greater<pair<ll, ll>>());
    sort(g, g + N, greater<pair<ll, ll>>());
    REP(i, 0, N) p[i] = f[i].second;
    REP(i, 0, N) q[i] = g[i].second;
  }

  ll x = f(-1, -1);

  REP(i, 0, N) {
    ll sx = 0, tx = 0;
    REP(j, 0, N) if (!b[j]) {
      if (A[i] < B[j]) s[sx++] = make_pair(B[j], j);
      else t[tx++] = make_pair(B[j], j);
    }
    sort(s, s + sx);
    sort(t, t + tx);

    bool z = sx > 0 && f(i, s[0].second) + 1 >= x;
    ll w = z ? 1 : 0;
    ll vx = z ? sx : tx;
    pair<ll, ll> *v = z ? s : t;

    ll l = 0, h = vx;
    while (h - l > 1) {
      ll m = (l + h) / 2;
      if (f(i, v[m].second) + w >= x) l = m;
      else h = m;
    }

    if (z) x--;
    a[i] = true;
    b[v[l].second] = true;
    ans[i] = v[l].first;
  }

  REP(i, 0, N) cout << ans[i] << (i + 1 == N ? "\n" : " ");
}


Measured memory_bytes: 3352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a=(n+1)/2;
    double ans=a/(double)n;
    cout<<fixed<<setprecision(10)<<ans<<'\n';




}


Measured memory_bytes: 3736
#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"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;
const double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> K;
	vector<int>box;
	vector<int>rev;
	for (int i = 1; i*i <= N; i++) {
		box.push_back(i);
		rev.push_back(N / i);
	}
	while (!rev.empty()) {
		if (rev.back() != box.back()) {
			box.push_back(rev.back());
		}
		rev.pop_back();
	}
	vector < vector<long long int> >dp(K + 1, vector<long long int>(box.size() + 1));
	for (int i = 0; i <= box.size(); i++) {
		if(!i)dp[1][i] = 1;
		else dp[1][i] = box[i] - box[i - 1];
	}
	for (int i = 2; i <= K; i++) {
		long long int sum = 0;
		for (int j = box.size() - 1; j >= 0; j--) {
			sum += dp[i - 1][box.size() - j - 1];
			sum %= MOD;
			if(!j)dp[i][j] = sum;
			else dp[i][j] = sum * (box[j] - box[j - 1]);
			dp[i][j] %= MOD;
		}
	}
	long long int ans = accumulate(dp.back().begin(), dp.back().end(), 0LL);
	cout << ans % MOD << endl;
}

Measured memory_bytes: 51324
unittest
{
	assert( [ "1", "2", "4", "8", "9", "15" ].parse.expand.solve == "Yay!" );
	assert( [ "15", "18", "26", "35", "36", "18" ].parse.expand.solve == ":(" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto a = input.front.to!( long );
	input.popFront;
	auto b = input.front.to!( long );
	input.popFront;
	auto c = input.front.to!( long );
	input.popFront;
	auto d = input.front.to!( long );
	input.popFront;
	auto e = input.front.to!( long );
	input.popFront;
	auto k = input.front.to!( long );
	return tuple( a, b, c, d, e, k );
}

auto solve( long a, long b, long c, long d, long e, long k )
{
	if( b - a <= k && c - a <= k && d - a <= k && e - a <= k &&
	    c - b <= k && d - b <= k && e - b <= k &&
	    d - c <= k && e - c <= k &&
	    e - d <= k )
	{
		return "Yay!";
	}
	else
	{
		return ":(";
	}
}


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

using namespace std;
const int N = 100010;
int _w;

int n, a[N];
map<int,int> cnt;

int main() {
	_w = scanf( "%d", &n );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d", a+i );
	for( int i = 1; i <= n; ++i )
		++cnt[a[i]];
	if( cnt.size() == 1 && cnt.begin()->first == 0 ) {
		puts("Yes");
	} else {
		if( n % 3 == 0 ) {
			if( cnt.size() == 3 ) {
				auto it = cnt.begin();
				int x = it->first;
				int xc = it->second;
				++it;
				int y = it->first;
				int yc = it->second;
				++it;
				int z = it->first;
				int zc = it->second;
				if( (x ^ y ^ z) == 0 && xc == yc && xc == zc ) {
					puts("Yes");
				} else {
					puts("No");
				}
			} else if( cnt.size() == 2 ) {
				auto it = cnt.begin();
				int x = it->first;
				int xc = it->second;
				++it;
				int y = it->first;
				int yc = it->second;
				if( x == 0 && yc == xc + xc ) {
					puts("Yes");
				} else {
					puts("No");
				}
			} else {
				puts("No");
			}
		} else {
			puts("No");
		}
	}
	return 0;
}


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

using namespace std;
int h[100005],f[100005];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	f[1]=0;
	f[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++){
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<f[n];
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

ans = 0

for i in range(1, N+1):
    # print(A1[:i], A2[i-1:])
    r = sum(A1[:i]) + sum(A2[i-1:])
    ans = max(ans, r)
print(ans)


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

#define ll long long
#define endl "\n"

struct item {
	int letters[26] = {0};
	int ans = 0;
};

item nothing = {{0}, 0};

struct segment_tree {
	int size;
	vector <item> res;

	void initiate(int n) {
		size = 1;
		while (size < n) size *= 2;
		res.resize(2 * size);
	}

	item single(char n) {
		item now = nothing;
		now.letters[n - 'a'] = 1;
		now.ans = 1;
		return now;
	}

	item merge(item &a, item &b) {
		item temp = nothing;
		int total = 0;
		for (int i = 0; i < 26; i++) {
			temp.letters[i] = a.letters[i] + b.letters[i];
			total += (temp.letters[i] > 0);
		}
		temp.ans = total;
		return temp;
	}

	void build(string &numbers, int index, int start, int end) {
		if (end - start == 1) {
			if (start < numbers.size()) {
				res[index] = single(numbers[start]);
			}
			return;
		}

		int mid = (start + end) / 2;

		build(numbers, index * 2 + 1, start, mid);
		build(numbers, index * 2 + 2, mid, end);

		res[index] = merge(res[index * 2 + 1], res[index * 2 + 2]);
	}

	void build(string &numbers) {
		build(numbers, 0, 0, size);
	}

	void set(int i, char v, int index, int start, int end) {
		if (end - start == 1) {
			res[index] = single(v);
			return;
		}

		int mid = (start + end) / 2;

		if (i < mid) {
			set(i, v, index * 2 + 1, start, mid);
		}
		else set(i, v, index * 2 + 2, mid, end);

		res[index] = merge(res[index * 2 + 1], res[index * 2 + 2]);
	}

	void set(int i, char v) {
		set(i, v, 0, 0, size);
	}

	auto calc(int l, int r, int index, int start, int end) {
		if (end <= l or start >= r) return nothing;
		if (start >= l and end <= r) return res[index];

		int mid = (start + end) / 2;

		auto s1 = calc(l, r, index * 2 + 1, start, mid);
		auto s2 = calc(l, r, index * 2 + 2, mid, end);

		return merge(s1, s2);
	}

	auto calc(int l, int r) {
		return calc(l, r, 0, 0, size);
	}

};

int main ()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, q;
	cin >> n;
	string word;
	cin >> word;
	//n = word.size();
	segment_tree st;
	st.initiate(n);
	st.build(word);

	cin >> q;
	while (q--) {
		int op;
		cin >> op;

		if (op == 2) {
			int l, r;
			cin >> l >> r;
			l--;
			cout << st.calc(l, r).ans << endl;
		}

		else {
			int i;
			char v;
			cin >> i >> v;
			i--;
			word[i] = v;
			st.set(i, v);
		}
	}
	return 0;

}


Measured memory_bytes: 114372